akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define SYOU(x) fixed<<setprecision(x) //小数点桁数を指定する
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
int main(){
    STR(s);
    STR(t);
    int ans = 0;
    for(int i = 0; i < s.size(); ++i){
        if(s[i] != t[i]){
            ans++;
        }
    }

    cout << ans << endl;
   
}

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

int main(){
  int n;
  cin >> n;
  vector<ll> A(n);
  ll cnt =0;
  ll ans =0;
  rep(i,n) {
    cin >> A[i];
    ans = ans%INF+A[i]*cnt;
    cnt = cnt%INF+A[i];
  }
  cout << ans % INF << endl;
  return 0;

}


Measured memory_bytes: 4788
H, W, M = map(int, input().split())

sumh = [0] * W
sumw = [0] * H
checkset = set()
for i in range(M):
    h, w = map(int, input().split())
    checkset.add((h-1, w-1))
    sumh[w-1] += 1
    sumw[h-1] += 1
shmax = max(sumh)
swmax = max(sumw)
sh = []
sw = []
for i, s in enumerate(sumh):
    if s == shmax: sh.append(i)
for i, s in enumerate(sumw):
    if s == swmax: sw.append(i)
ans = shmax + swmax - 1
jdg = False
for i in sh:
    for j in sw:
        if (j, i) not in checkset: 
            ans += 1
            jdg = True
            break

    if jdg: break
print(ans)


Measured memory_bytes: 83540
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(K, X):
    return 'Yes' if 500*K >= X else 'No'


def main():
    K, X = read_int_n()
    print(slv(K, X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7740
def solve():
    N = int(input())

    dp = [float('inf')] * (N+1)
    dp[0] = 0

    for i in range(N):
        k = 0
        while 6 ** k + i<= N:
            dp[6 ** k + i] = min(dp[6**k + i], dp[i] + 1)
            k += 1

        k = 0
        while 9 ** k + i <= N:
            dp[9 ** k + i] = min(dp[9**k+i], dp[i] + 1)
            k += 1
        
        dp[i+1] = min(dp[i+1], dp[i] + 1)

    print(dp[-1])
if __name__ == '__main__':
    solve()


Measured memory_bytes: 46032
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)

    void yes(bool fl = true){
            if(fl) cout << "YES\n";
            else cout << "Yes\n";
    }
    void no(bool fl = true){
        if(fl) cout << "NO\n";
        else cout << "No\n";
    }  

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;
        

        


        

        void solve(){
          cin >> k >> a >> b;
          for(;a<=b;a++){
              if(a%k==0){
                  cout<<"OK";
                  return;
              }
          }
          cout <<"NG";
            
        }
    
   

        int main(){
        ios_base::sync_with_stdio(false);
       

        int cases = 1;
        //cin >> cases;

        while(cases--){ 
            solve();
        }

        return 0;

        }

Measured memory_bytes: 3612
#include <stdio.h>
#define N 100 

int main () {
  int i, j, A[N], n = 0, tmp = 0, cnt = 0;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) {
    scanf("%d",&A[i]);
  }

  for(i = 0 ; i < n ; i++) {
    for(j = n - 1 ; j >= i + 1 ; j--) {
      
      if(A[j] < A[j - 1]) {
	tmp = A[j];
	A[j] = A[j - 1];
	A[j - 1] = tmp;
	cnt++;
      }
      
    }
  }

  for(i = 0 ; i < n ; i++) {
    if(i == n - 1) printf("%d\n",A[i]);
    else printf("%d ",A[i]);
  }

  printf("%d\n",cnt);
  
  return 0;
}



Measured memory_bytes: 2068
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))




int main(){
	int L,A,B,C,D;
	cin>>L>>A>>B>>C>>D;
	cout<<L-max(ceil((double)A/C),ceil((double)B/D))<<endl;;
	
	return 0;
}

Measured memory_bytes: 1236
h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
left=[[0]*w for _ in range(h)]
right=[[0]*w for _ in range(h)]
up=[[0]*w for _ in range(h)]
down=[[0]*w for _ in range(h)]
for i in range(h):
    temp=1
    for j in range(w):
        if s[i][j]==".":
            left[i][j]+=temp
            temp+=1
        else:
            temp=1
for i in range(h):
    temp=1
    for j in range(w)[::-1]:
        if s[i][j]==".":
            right[i][j]+=temp
            temp+=1
        else:
            temp=1
for i in range(w):
    temp=1
    for j in range(h):
        if s[j][i]==".":
            down[j][i]+=temp
            temp+=1
        else:
            temp=1
for i in range(w):
    temp=1
    for j in range(h)[::-1]:
        if s[j][i]==".":
            up[j][i]+=temp
            temp+=1
        else:
            temp=1
ans=1
for i in range(h):
    for j in range(w):
        ans=max(ans,up[i][j]+down[i][j]+left[i][j]+right[i][j]-3)
print(ans)

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

int main() {
  int A,B,C,X; 
  cin>>A>>B>>C>>X;
  int ans;
  rep(i,A+1){
    rep(j,B+1){
      rep(k,C+1){
        if(i*500+j*100+k*50==X)ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
def f(i, k):
    if i == n and k == 0:
        global d
        hr1, hb1 = 0, 0
        hr2, hb2 = 0, 0
        cntr, cntb = 0, 0
        for j in range(n):
            if c[j]:
                hr1 += x[j] * pow(b1, cntr, mod)
                hr2 += x[j] * pow(b2, cntr, mod)
                hr1 %= mod
                hr2 %= mod
                cntr += 1
            else:
                hb1 += x[j] * pow(b1, cntb, mod)
                hb2 += x[j] * pow(b2, cntb, mod)
                hb1 %= mod
                hb2 %= mod
                cntb += 1
        if min(cntr, cntb) == 0:
            return
        if (hr1, hr2, hb1, hb2) in d:
            d[(hr1, hr2, hb1, hb2)] += 1
        else:
            d[(hr1, hr2, hb1, hb2)] = 1
        return
    elif i == n and k == 1:
        hr1, hb1 = 0, 0
        hr2, hb2 = 0, 0
        cntr, cntb = 0, 0
        for j in range(n):
            if c[j]:
                hr1 += y[j] * powb1[cntr]
                hr2 += y[j] * powb2[cntr]
                hr1 %= mod
                hr2 %= mod
                cntr += 1
            else:
                hb1 += y[j] * powb1[cntb]
                hb2 += y[j] * powb2[cntb]
                hb1 %= mod
                hb2 %= mod
                cntb += 1
        if min(cntr, cntb) == 0:
            return
        if (hr1, hr2, hb1, hb2) in d:
            global ans
            ans += d[(hr1, hr2, hb1, hb2)]
        return
    c[i] = 1
    f(i + 1, k)
    c[i] = 0
    f(i + 1, k)


n = int(input())
s = list(input())
mod = pow(2, 31) - 1
b1, b2 = 27, 31
powb1 = [pow(27, i, mod) for i in range(n)]
powb2 = [pow(31, i, mod) for i in range(n)]
d = {}
x, y = [], []
for i in range(n):
    x.append(ord(s[i]) - 96)
    y.append(ord(s[-(i + 1)]) - 96)
ans = 0 if not x == y else 2
c = [0] * n
f(0, 0)
c = [0] * n
f(0, 1)
print(ans)

Measured memory_bytes: 163080
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    ll x, y;
    cin >> x >> y;
    ll ans = 1;
    while(x < y) {
        x *= 2;
        if(x <= y) {
            ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <queue>
#include <vector>
#include <stdio.h>

using namespace std;

const int maxn = 1e5 + 5;
int n, m;
vector <int> C[maxn];
priority_queue <pair <int, pair <int, int> > > pq;
map <int, int> dis[maxn];
map <int, vector <int> > G[maxn];

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i ++) {
		int u, v, c;
		scanf("%d%d%d", &u, &v, &c);
		G[u][c].push_back(v);
		G[v][c].push_back(u);
		C[u].push_back(c);
		C[v].push_back(c);
	}
	dis[1][0] = 0;
	pq.push(make_pair(0, make_pair(1, 0)));
	while (!pq.empty()) {
		pair <int, pair <int, int> > p = pq.top();
		pq.pop();
		int u = p.second.first, c = p.second.second;
		if (dis[u][c] < - p.first) continue;
		if (!dis[u].count(0) || dis[u][0] > dis[u][c]) {
			dis[u][0] = dis[u][c];
			pq.push(make_pair(-dis[u][0], make_pair(u, 0)));
		}
		if (!c) {
			for (int i = 0; i < (int) C[u].size(); i ++) {
				int nc = C[u][i];
				if (!dis[u].count(nc) || dis[u][nc] > dis[u][c] + 1) {
					dis[u][nc] = dis[u][c] + 1;
					pq.push(make_pair(-dis[u][nc], make_pair(u, nc)));
				}
			}
		}
		else {
			for (int i = 0; i < (int) G[u][c].size(); i ++) {
				int v = G[u][c][i];
				if (!dis[v].count(c) || dis[v][c] > dis[u][c]) {
					dis[v][c] = dis[u][c];
					pq.push(make_pair(-dis[v][c], make_pair(v, c)));
				}
			}
		}
	}
	int ans = 1000000007;
	for (map <int, int> :: iterator it = dis[n].begin(); it != dis[n].end(); it ++) {
		if (it -> second < ans) {
			ans = it -> second;
		}
	}
	printf("%d\n", ans >= 1000000007 ? -1 : ans);
	return 0;
}


Measured memory_bytes: 84148
N,K = map(int,input().split())

items = list(tuple(map(int,input().split())) for _ in range(N))

l = K.bit_length()

def it():

  for i in range(l):
    if K & (1 << i):
      j = (K-(1<<i))|((1<<i)-1)
      j = ~j
      yield sum(b for a,b in items if a&j==0)
  j = ~K
  yield sum(b for a,b in items if a&j==0)

print(max(it()))

Measured memory_bytes: 16864
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;


int Main(int a, int b)
{
    if(a == 1) {
        if(b == 2) return 3;
        else return 2;
    }
    if(a == 2) {
        if(b == 1) return 3;
        else return 1;
    }
    if(a == 3) {
        if(b == 1) return 2;
        else return 1;
    }
}

int main(void){
    int A, B;
    cin >> A;
    cin >> B;
    cout << Main(A, B) << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<string, int>;

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

struct Rest {
  int id;
  string s;
  int p;

  Rest(int _id, string _s, int _p) : id(_id), s(_s), p(_p) {}

  bool operator<(const Rest &right) const {
    return s == right.s ? p > right.p : s < right.s;
  }
};

int main() {
  int n;
  cin >> n;
  vector<Rest> r;
  rep(i, n) {
    string s;
    int p;
    cin >> s >> p;
    r.push_back(Rest(i + 1, s, p));
  }

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

  for (auto re : r) cout << re.id << endl;

  return 0;
}


Measured memory_bytes: 3608
H, W = map(int, input().split())
grid = [list(input()) for i in range(H)]
diff = [(1,0), (-1, 0), (0, 1), (0, -1)]

for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            flag = False
            for d in diff:
                if 0 <= i + d[0] < H and 0 <= j + d[1] < W:
                    if grid[i+d[0]][j+d[1]] =='#':
                        flag = True
            if not flag:
                print('No')
                exit()
print('Yes')
                    
                    


Measured memory_bytes: 3064
#include <iostream>
#include<string>
using namespace std;
int main(void){
    // Your code here!
    int N;
    
    cin >> N;
    
    int cont = 0;
    
    for(int i = 1; i <= N ;i++){
        
        if(to_string(i).length()%2!=0)cont++;
        
    }
    
    cout << cont << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll N,a;
    vector<ll> A;
    cin >> N;
    REP(i,N){
        cin >> a;
        A.push_back(a);
    }
    
    ll Ans=0;
    sort(A.begin(),A.end(),greater<>());
    
    REP(i,N){
        if(i==0)continue;
        Ans+=A[i/2];
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 5308
using System;
using System.Linq;

namespace _3_C
{
    class Program
    {
        static void Main(string[] args)
        { 
            bool z = true;

           while (z)
            {
                int[] x1 = Console.ReadLine().Split().Select(int.Parse).ToArray();

                if (!(x1[0]==0&&x1[1]==0))
                {
                
                    Array.Sort(x1);
                    Console.WriteLine(x1[0]+" "+x1[1]);
                }
                else
                {
                    z = false;
                }
            }
        }
    }
}

Measured memory_bytes: 9960
import java.util.*;

public class Main {

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

		String s = sc.next();
		char[] S = s.toCharArray();

		int c = 0;
		boolean rain = false;
		for (int i = 0; i<2; i++) {
			if (S[i] == S[i+1] && S[i] == 'R') {
				c++;

			}
		}
		for (int i = 0; i<3;i++) {
			if (S[i] == 'R') {
				rain = true;
			}
		}
		if (rain) {
			System.out.println(c+1);
		} else {
			System.out.println(0);
		}
	}
}

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

int rcheck(int in){
  for(int i = 1; i <= 5; i++){
    if(i*100 > in) return i-1;
  }
}

int tcheck(int in){
  for(int i = 0; i <= 6; i++){
    if(i*30 > in) return i;
  }
}

int main()
{
  int point[5][7];
  for(int i = 0; i <= 6; i++){
    for(int j = 0; j <= 4; j++){
      point[j][i] = i*5 + 1 + j;
    }
  }


  int n;
  cin >> n;

  vector<int> r(n);
  vector<int> t(n);

  int len, rag, x, x2;

  for(int i = 0 ; i < n; i++) {
    cin >> r[i] >> t[i];

    if(r[i] % 100 == 0){
      len = r[i] / 100 - 1;

      if(t[i] % 30 == 0) cout << point[len][t[i] / 30] << endl;

      else {
	x = tcheck(t[i]);
	cout << point[len][x - 1] << " " << point[len][x] << endl;
      }
    }

    else if(t[i] % 30 == 0){
      rag = t[i] / 30;
      x = rcheck(r[i]);
      cout << point[x-1][rag] << " " << point[x][rag] << endl;
    }

    else{
      x = rcheck(r[i]);
      x2 = tcheck(t[i]);

      cout << point[x - 1][x2 - 1] << " " << point[x][x2-1] << " " << point[x-1][x2] << " " << point[x][x2] << endl;
    }

  }

  return 0;

}



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

using namespace std;
typedef long long ll;

int main() {
    while (true) {
        ll n, m, a, b, c, t;
        cin >> n >> m >> a >> b >> c >> t;
        if (max({n, m, a, b, c, t}) == 0)break;

        vector<vector<vector<ll>>> edge(40, vector<vector<ll>>(n, vector<ll>(n)));
        for (int i = 0; i < n; i++) {
            if (i > 0)edge[0][i][i - 1] = c;
            edge[0][i][i] = b;
            if (i + 1 < n)edge[0][i][i + 1] = a;
        }

        for (int i = 1; i < 40; i++) {
            for (int from = 0; from < n; from++) {
                for (int mid = 0; mid < n; mid++) {
                    for (int to = 0; to < n; to++) {
                        edge[i][from][to] += edge[i - 1][from][mid] * edge[i - 1][mid][to];
                        edge[i][from][to] %= m;
                    }
                }
            }
        }

        vector<ll> dp(n);
        for (int i = 0; i < n; i++)cin >> dp[i];

        for (int i = 0; i < 40; i++) {
            if ((t >> i) & 1) {
                vector<ll> after(n);
                for (int j = 0; j < n; j++) {
                    for (int k = 0; k < n; k++) {
                        after[k] += edge[i][j][k] * dp[j];
                        after[k] %= m;
                    }
                }
                dp = after;
            }
        }

        for (int i = 0; i < n; i++) {
            if (i > 0)cout << " ";
            cout << dp[i];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3612
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

void swap(int a,int b) {
	int tmp = a;
	a = b;
	b = tmp;
}

int main(void) {
	ll x;
	cin >> x;
	ll ans = 0;

	if (x>=500) {
		ll a = x / 500;
		ans += 1000*a;
		x-=500*a;
	}

	if (x >= 5) {
		ll a = x / 5;
		ans += 5 * a;
	}


	
	cout << ans << endl;
	


	

	return 0;
}

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

int main(void)
{
  int d;
  cin>>d;
  if(d==25)
  cout<<"Christmas"<<endl;
  else if(d==24)
  cout<<"Christmas Eve"<<endl;
  else if(d==23)
  cout<<"Christmas Eve Eve"<<endl;
  else
  cout<<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 10;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i, sz(v)) { if (i) os << " "; os << v[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
inline int add(int a, int b) { a += b; if (a >= mod) return a - mod; return a; }

void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


void solve() {
  int n;
  cin >> n;
  vector<int> s(n);
  rep(i, n) cin >> s[i];

  ll ans = 0;
  rep3(c, 1, n) { // 座標は0 ~ n-1
    ll tmp = 0;
    int flg = 0;
    set<int> st;
    rep(x, n) {
      int a = (n - 1) - x * c; // どんどん小さくなる
      int b = a - c; // どんどん小さくなる
      if (a <= 0 || b <= 0) break; // x, c, 調和級数 計算量

      int k1 = x * c; // どんどん大きくなる
      int k2 = a;

      if (k1 == k2 || k1 >= n || k2 < 0) break;
      if (st.count(k1) || st.count(k2)) break;
      st.insert(k1);
      st.insert(k2);

      tmp += s[k1];
      tmp += s[k2];
      chmax(ans, tmp);
    }
  }
  cout << ans << endl;
}


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

int main()
{

  int a,b,x,y,r,migi,hidari,ue,sita = 0;

  cin >> a >> b >> x >> y >> r;
  
  migi = x+r;
  ue = y+r;
  hidari = x-r;
  sita = y-r;
  
  if(0 <= hidari && 0 <= sita){
    if(a >= migi && b >= ue){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 1160
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll mod = 1000000007, oo = 1000000009;

void Emsawy() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

#define clr(v,d)     memset(v, d, sizeof(v))
#define sz(v)	     ((int)((v).size()))
#define all(v)	     ((v).begin()), ((v).end())
#define allr(v)	     ((v).rbegin()), ((v).rend())
#define V	         vector
#define MP	         make_pair
#define bug(n)           cout<< #n <<" = "<< n << endl;
int dx[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dy[] = { 0, 0, 1, -1, 1, -1, -1, 1 };

V<V<int> > adj;
const ll N = 100000 + 5;
int n, m, k, w;

int main() {

	//Emsawy();
	int a, b; 
	while (cin >> a >> b) {
		if (a == 0) cout << (b == 100? 101 : b) << endl;
		else if (a == 1) cout << (b == 100 ? 101 : b) << "00" << endl;
		else cout << (b == 100 ? 101 : b) << "0000" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(void)
{
    int A,B,N;
    scanf("%d%d%d",&N,&A,&B);
    if(N==1)
    {
        if(A==B)
            printf("1\n");
        else
            printf("0\n");
    }
    else 
    {
        if(A>B)
            printf("0\n");
        else
            printf("%lld\n",(long long )(B-A)*(N-2)+1);
    }
    return 0;;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N;
    cin >> N;

    vector<int> score(N);
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> score[i];
        sum += score[i];
    }
    if (sum % 10 != 0)
    {
        cout << sum << "\n";
        return (0);
    }

    sort(score.begin(), score.end());
    for (int i = 0; i < score.size(); i++)
    {
        if (score[i] % 10 != 0)
        {
            sum -= score[i];
        }

        if (sum % 10 != 0)
        {
            cout << sum << "\n";
            return (0);
        }

        // temp = to_string(score[i]);
        // if (temp[temp.size() - 1] == '5')
        // {
        //     sum -= score[i];
        //     break;
        // }
    }
    if (sum % 10 == 0)
    {
        sum = 0;
    }
    cout << sum << "\n";
    return (0);
}

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

int main(){
  int n;  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(), v.end());
  double ans = v[0];
  rep(i,n){
    if(i==0) continue;
    ans = (v[i]+ans)/2;
  }
  printf("%.7f\n", ans);
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <fstream>
using namespace std;
#define INF 0x3f3f3f3f
int main() {
	int n;
	cin >> n;
	cout << n / 2 + n % 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  if(a==1 && b==1) {
    cout << 1 << endl;
    return 0;
  }
  if(a==1) {
    cout << b-2 << endl;
    return 0;
  }

  if(b==1) {
    cout << a-2 << endl;
    return 0;
  }

  cout << a*b-2*(a+b-2) << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
int A[N][N]={0};

void list(int);

int main(){
  int n,i,j,k,l,m;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&k,&l);
    for(j=0;j<l;j++) {
      scanf("%d",&m);
      A[i][m-1]=1;
    }
  }
  list(n);
  return 0;
}

void list(int n){
  int i,j;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j==n-1)printf("%d",A[i][j]);
      else printf("%d ",A[i][j]);
    }
    printf("\n");
  }
  return ;
}
      

Measured memory_bytes: 636
#include<iostream>
#include<cmath>

using namespace std;

int main(void){
  int x,y,z,n,r;

  while(cin >> x >> y >> z,x|y|z){

    double a,b,c;
    a=sqrt(x*x+y*y);
    b=sqrt(y*y+z*z);
    c=sqrt(z*z+x*x);
    
    cin >> n;
    while(n--){
      cin >> r;
      r*=2;
      if(r>a||r>b||r>c)cout << "OK" << endl;
      else cout << "NA" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <queue>
using namespace std;
#define INF 9999999

int graph[101][101];
int dis[101]; //距離を格納
bool check[101];//訪問済みチェック
int main(){
  int n;
  cin>>n;
  fill(dis,dis+101,INF);
  dis[1]=0;
  check[1]=true;
  for(int i=0;i<n;i++){
    int u,k,v;
    cin>>u>>k;
    for(int j=1;j<=k;j++){
      graph[u][0]=k;
      cin>>graph[u][j];
    }
  }
  queue<int> qu;
  qu.push(1);
  while(!qu.empty()){
    int num=qu.front(); qu.pop();
    for(int j=1;j<=graph[num][0];j++){
      int temp=graph[num][j];
      if(check[temp]){//訪問済みならば
        continue;
      }else{
        check[temp]=true;
      }
      dis[temp]=dis[num]+1;
      qu.push(temp);
    }
  }
  //表示部
  for(int i=1;i<=n;i++){
    cout<<i<<" ";
    if(dis[i]>=INF)cout<<-1<<"\n";
    else  cout<<dis[i]<<"\n";
  }
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
using namespace std;
pair<long long,long long> p[100005];
int main()
{
    long long n,m;
    cin>>n>>m;
    for(long long i=0;i<n;i++)
    {
        long long x,y;
        cin>>x>>y;
        p[i]=mp(x,y);
    }
    sort(p,p+n);
    long long ans=0;
    for(long long i=0;i<n;i++)
    {
        if(m<=0)
            break;
        if(m-p[i].S>=0)
            ans+=p[i].S*p[i].F;
        else
            ans+=m*p[i].F;
        m-=p[i].S;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	vector<int>a;
	vector<int>b;
	vector<int>c;
	vector<long long>d;
	long long k, s;
	int n, m;
	long long x, y, z;
	long long ans = 0;

	scanf("%d", &n);

	f(i, n){
		scanf("%d", &m);
		a.push_back(m);
	}
	f(i, n){
		scanf("%d", &m);
		b.push_back(m);
	}
	f(i, n){
		scanf("%d", &m);
		c.push_back(m);
	}
	sort(a.begin(), a.end(), greater<int>());
	sort(b.begin(), b.end(), greater<int>());
	sort(c.begin(), c.end(), greater<int>());
	x = 0;
	y = 0;
	s = 0;
	for (; x < n;){
		if (y == n){
			s += y;
			d.push_back(s);
			x++;
		}
		else if (b[x] < c[y]){
			y++;
		}
		else {
			s += y;
			d.push_back(s);
			x++;
		}
	}
	x = 0;
	y = 0;
	for (; x < n;){
		if (y == n){
			ans += d[y - 1];
			x++;
		}
		else if (a[x] < b[y]){
			y++;
		}
		else {
			if (y > 0)ans += d[y - 1];
			x++;
		}
	}


	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 2552
N = int(input())
cs = [i for i in input()]
n_R = 0
for c in cs:
    if c == 'R':
        n_R += 1
n_n_R = 0
for i in range(n_R):
    if cs[i] == 'R':
        n_n_R += 1
print(n_R - n_n_R)


Measured memory_bytes: 10988
// AOJ 0246: Bara-Bara Manju
// 2017.10.30 bal4u@uu

#include <stdio.h>
#include <string.h>

int f[10];
int ans, sum, tmp;

int pair[36][5][2] = {
{{1,2},{8,1}}, {{1,1},{2,1},{7,1}}, {{1,1},{3,1},{6,1}}, {{1,1},{4,1},{5,1}}, {{2,2},{6,1}},       {{2,1},{3,1},{5,1}}, {{2,1},{4,2}}, {{3,2},{4,1}}, 
{{1,3},{7,1}}, {{1,2},{2,1},{6,1}}, {{1,2},{3,1},{5,1}}, {{1,2},{4,2}},       {{1,1},{2,2},{5,1}}, {{1,1},{2,1}, {3,1},{4,1}}, {{1,1},{3,3}}, {{2,3},{4,1}}, {{2,2},{3,2}}, 
{{1,4},{6,1}}, {{1,3},{2,1},{5,1}}, {{1,3},{3,1},{4,1}}, {{1,2},{2,2},{4,1}}, {{1,2},{2,1},{3,2}}, {{1,1},{2,3},{3,1}}, {{2,5}}, 
{{1,5},{5,1}}, {{1,4},{2,1},{4,1}}, {{1,4},{3,2}},       {{1,3},{2,2},{3,1}}, {{1,2},{2,4}}, 
{{1,6},{4,1}}, {{1,5},{2,1},{3,1}}, {{1,4},{2,3}}, 
{{1,7},{3,1}}, {{1,6},{2,2}}, 
{{1,8},{2,1}}, 
{{1,10}}};

int take(int k)
{
	int i, a;
	for (i = 0; (a = pair[k][i][0]) > 0; i++) if (f[a] < pair[k][i][1]) return 0;
	for (i = 0; (a = pair[k][i][0]) > 0; i++) f[a] -= pair[k][i][1];
	sum -= 10; tmp++;
	return 1;
}

void back(int k)
{
	int i, a;
	for (i = 0; (a = pair[k][i][0]) > 0; i++) f[a] += pair[k][i][1];
	sum += 10; tmp--;
}

void rec(int k)
{
	int i;
	for (i = k; ans < sum/10 + tmp && i < 36; i++) if (take(i)) rec(i), back(i);
	if (tmp > ans) ans = tmp;
}

int main()
{
	int n, i, k;

	while (scanf("%d", &n) && n > 0) {
		memset(f, 0, sizeof(f));
		while (n-- > 0) scanf("%d", &k), f[k]++;
		for (ans = 0, i = 9; i >= 6; i--) {
			k = f[i]; if (f[10-i] < k) k = f[10-i];
			ans += k, f[i] -= k, f[10-i] -= k;
		}
		ans += f[5]/2, f[5] &= 1; f[9] = 0;
		for (sum = 0, i = 1; i < 10; i++) sum += i*f[i];
		tmp = ans;
		rec(0);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1824
#include<cstdio>
#include<algorithm>

using namespace std;

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

int dp[50][2][3001];

int main(){
	
	int n,m,s,nn,st,i,j,k;
	int t1=0,t2=1;
	while(1){
		scanf("%d%d%d",&n,&m,&s);
		if(n==0)break;
		
		t1=0;
		t2=1;
		n*=n;
		rep(i,50)rep(j,2)rep(k,s+1)dp[i][j][k]=0;
		dp[0][0][0]=1;
		reps(j,m){
			
			dp[0][t2][0]=1;
			
			reps(i,n){
				nn=i;
				st=(nn*(nn+1))/2;
				int mm,pp,end;
				mm=(j-1)/2;
				if(j%2==0)pp=j/2;
				else pp=0;
				
				end= min(mm*(mm+1) + pp + st,s+1);
				
				for(k=st-1;k<=end;k++){
					dp[i][t2][k]=0;
					if(k-j>=0){
						dp[i][t2][k]+=dp[i-1][t1][k-j];
					}
					dp[i][t2][k]+=dp[i][t1][k];
					if(dp[i][t2][k]<0)puts("AAAAAAA");
					dp[i][t2][k]%=100000;
				}
				/*
				if(i<9&&j<12){
					printf("%d %d\n",i,j);
					for(int k=0;k<50;k++){
						printf("%d ",dp[i][t2][k]);
					}puts("");
				}*/
			}
			swap(t1,t2);
		}
		
		printf("%d\n",dp[n][t1][s]);
	}
}

Measured memory_bytes: 1928
#include<stdio.h>
int main(void)
{
	int a,b,c,i,n;
	scanf("%d %d %d",&a,&b,&c);
	i=0;
	n=0;
	while(1){
		if(n>=c){
			break;
		}
		i=i+1;
		n=n+a;
		if(i%7==0){
			n=n+b;
		}
	}
	printf("%d\n",i);
	return 0;
}	


Measured memory_bytes: 2148
#include "bits/stdc++.h"

const int size = 3e3 + 5;

int n;

double dp[size]{ 1.0 };

int main()
{
	std::cout << std::fixed << std::setprecision(12);
	std::cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		double x;
		std::cin >> x;
		for (int j = i; j > 0; --j)
		{
			dp[j] = dp[j] * (1.0 - x) + dp[j - 1] * x;
		}
		dp[0] = dp[0] * (1.0 - x);
	}
	double ans = 0.0;
	for (int i = 0; i <= n; ++i)
	{
		if (2 * i > n)
		{
			ans += dp[i];
		}
	}
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3764
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n, m) = get!(usize, usize);
    let uv = get!(usize, usize;m);
    let (s,t) = get!(usize, usize);

    let mut nodes = vec![Vec::new(); 3*(n+1)];
    for (u,v) in uv {
        nodes[u].push(n+v);
        nodes[u+n].push(2*n+v);
        nodes[u+2*n].push(v);
    }

    let mut queue = VecDeque::new();
    let mut visited = vec![false; 3*(n+1)];
    queue.push_back((s, 0));
    visited[s] = true;
    while let Some((node,dep)) = queue.pop_front() {
        if node == t {
            println!("{}", dep/3);
            return;
        }
        for &next in &nodes[node] {
            if visited[next] {
                continue;
            }
            queue.push_back((next, dep+1));
            visited[next] = true;
        }
    }
    println!("-1");
}


Measured memory_bytes: 27004
#include<cstdio>
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<queue>
using  ll = long long;
using namespace std;

int main(){
  int x, a, b; cin >> x >> a >> b;
  if(b <= a) cout << "delicious" << endl;
  else if (a + x >= b) cout << "safe" << endl;
  else cout << "dangerous" << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner itr = new Scanner(System.in);
        int K = itr.nextInt();
        int N = itr.nextInt();
        int[] place = new int[N];

        for (int i = 0; i < N; i++) {
            place[i] = itr.nextInt();
        }
        Arrays.sort(place);
        int max = K - place[N - 1] + place[0];
        for (int i = 1; i < N; i++) {
            max = Math.max(max, place[i] - place[i - 1]);
        }

        System.out.println(K - max);
    }
}

Measured memory_bytes: 66948
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
struct __test {} test;
using namespace std;
template <typename T>const __test &operator<<(const __test& d,
const T& v) {return cerr << "\033[31m" << v << "\033[0m",d;}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

bool b[2500]={};

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	string s;
	cin >> s;
	for(char c : s)
		b[c] = 1;
	if(b['S'] != b['N'] || b['E'] != b['W']) cout << "No\n";
	else cout << "Yes\n";
}

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

int main(){
    int n;
    cin >> n;

    int x = (25 * n + 26) / 27;

    if(x * 27 / 25 == n){
        cout << x << endl;
    }else{
        cout << ":(" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
#define MAX 1000000
int main(){
    string sa;
    int n;
    int sum=0;
    cin >> sa;
    n = sa.size();
    for(int i=0;i<n;i++){
        sum += sa[i]-48;
    }
    if(sum%9 == 0){
        cout << "Yes" << endl;
    }else if(sum==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    if (n % x == 0) {
        cout << n / x * t << endl;
    }
    else {
        cout << (n / x + 1) * t << endl;
    }
    return 0;
}

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

int main() {
    int N, K;
    int l[50];

    cin >> N >> K;

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

    sort(l, l + N);
    reverse(l, l + N);

    int sum = 0;

    for (int i = 0; i < K; i++) {
        sum += l[i];
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N,K=map(int,input().split())
V=list(map(int,input().split()))

left=[0]
right=[0]

for n in range(N):
    left.append(V[n]+left[n])
for n in range(N):
    right.append(V[-n-1]+right[n])

#print(left)
#print(right)

dp=[[0]*(K+1) for _ in range(K+1)]

for l in range(min(K+1,N+1)):
    for r in range(min(K-l+1,N-l+1)):
        dp[l][r]=left[l]+right[r]
        if N>l+r:
            temp=V[:l]+V[::-1][:r]#ここが不味い
        else:
            temp=V[:]
        #print(V,l,r,temp)
        temp.sort()
        
        #for i in range(min(K-l-r,N-l-r)):
        for i in range(K-l-r):
            #ここでマイナス項を引きたい
            if len(temp)==0 or temp[0]>=0:
                break
            else:
                e=temp.pop(0)
                #print(e)
                dp[l][r]-=e
                
ans=0
for item in dp:
    for obj in item:
        ans=max(ans,obj)
#print(dp)
print(ans)



Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
const int SZ=2005;
ll combi[SZ][SZ];
ll dp(int a, int b){
	if(a<b) return 0LL;
	if(a==b) return 1LL;
	if(b==0) return 1LL;
	if(combi[a][b]!=0LL) return combi[a][b];
	return combi[a][b]=(dp(a-1,b-1)+dp(a-1,b))%MOD;
}
int main(void){
	int n,m; scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++){
		printf("%lld\n",dp(m-1,i-1)*dp(n-m+1,i)%MOD);
	}
	return 0;
}

Measured memory_bytes: 30208
#include<iostream>

using namespace std; 

int main()
{
	int a,b,k,th=0,m;
	cin>>a>>b>>k;
	a>b?m=b:m=a;
	for(int i=a;i>0;i--)
	if(a%i==0&&b%i==0)
	{
		th++;
		if(th==k)
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
bai4_count=0
bai2_count=0
no = 0

N = int(input())
a = list(map(int,input().split()))

for i in range(N):
    if a[i]%4==0:
        bai4_count+=1
    elif a[i]%2==0:
        bai2_count+=1
    else:
        no+=1
ans = False
if bai2_count>0:
    if bai4_count >= no:
        ans=True
    else:
        ans=False
else:
    if bai4_count+1 >= no:
        ans=True
    else:
        ans=False

print("Yes" if ans else "No")

Measured memory_bytes: 84828
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner) = {
    println((sc.nextInt - sc.nextInt) % sc.nextInt)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}



Measured memory_bytes: 25644
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))

N, M , Q = mi()
LR = li2(M)

dp = dp2(0, N+1, N+1)

for l, r in LR:
    dp[l][r] += 1

for i in range(N+1):
    dp[i] = list(accumulate(dp[i]))

for i in range(1, N+1):
    for j in range(N+1):
        dp[i][j] += dp[i-1][j]

for _ in range(Q):
    f, t = mi()
    f_ = max(0, f-1)
    print(dp[t][t] - dp[f_][t] - dp[t][f_] + dp[f_][f_])

Measured memory_bytes: 56220
#include <bits/stdc++.h>
using namespace std;
int main() {
	char a; cin >> a;
	switch (a){
		case 'A': cout << 'T'; break;
		case 'T': cout << 'A'; break;
		case 'G': cout << 'C'; break;
		case 'C': cout << 'G'; break;
	}
}

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

int n,c[501],s[501],f[501],t[501],ct;

int main(){
	cin >> n;
	for(int i=1; i<n; i++) cin >> c[i] >> s[i] >> f[i];

	for(int k=1; k<n; k++){
		ct = 0;
		for(int i=k; i<n; i++){
			if(ct < s[i]) ct = s[i];
			else{
				if(ct % f[i]) ct = ((ct/f[i])+1)*f[i];
			}
			ct += c[i];
		}
		cout << ct << endl;
	}
	cout<< 0 << endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 1; i <= 5; i++) {
            if(sc.nextInt() == 0) {
                System.out.println(i);
                break;
            }
        }
    }
}


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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll a,b,c,d;cin>>a>>b>>c>>d;

  rep(i,0,102){
    c-=b;
    if(c<=0){
      out("Yes");
      return 0;
    }

    a-=d;
    if(a<=0){
      out("No");
      return 0;
    }

  }


  return 0;
}


Measured memory_bytes: 3636