akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    int ans = 0;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    sort(L.begin(), L.end());
    rep(i, N-2) for(int j = i+1; j < N-1; j++) for(int k = j+1; k < N; k++){
        if(L[j] > L[k]-L[i]) ans++;
        else break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
//using ll = long long;
using namespace std;

void CountingSort(vector<int> &a, vector<int> &b, int k){
	int n = a.size();
	vector<int> c(k+1, 0);
	rep(j, n){
		c.at(a.at(j))++;
	}

	rep2(i, 1, k+1){
		c.at(i) = c.at(i) + c.at(i-1);
	}

	rrep(i, n){
		b.at(c.at(a.at(i))-1) = a.at(i);
		c.at(a.at(i))--;
	}
}

int main(){
	int n, mx = 0;
	cin >> n;
	vector<int> a(n), b(n);
	rep(snip_i, n){
		cin >> a.at(snip_i);
		mx = max(mx, a.at(snip_i));
	}
	CountingSort(a, b, mx);
	rep(i, n){
		if(i != 0) cout << " ";
		cout << b.at(i);
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 18336
# coding: utf-8

n = int(input().rstrip())
wi = [int(i) for i in input().rstrip().split()]
visited = [False for i in range(n)]
minw = min(wi)
dict = {}
for i, v in enumerate(sorted(wi)):
    dict[v] = i

ans = 0
for i in range(n):
    if visited[i]:
        continue
    cnt = 0
    now = i
    mi = 100000
    s = 0
    while True:
        if visited[now]:
            break
        cnt += 1
        visited[now] = True
        mi = min(mi, wi[now])
        s += wi[now]
        now = dict[wi[now]]
    
    tmp = s + (cnt-2)*mi
    tmp = min(tmp, s+mi+minw*(cnt+1))
    ans += tmp

print(ans)
    


Measured memory_bytes: 5724
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  string s; cin >> s;
  ll i = s.size();
  while (i > 4) {
    if (s.substr(i-5, 5) == "dream") i -= 5;
    else if (s.substr(i-5, 5) == "erase") i -= 5;
    else if (i >= 6 && s.substr(i-6, 6) == "eraser") i -= 6;
    else if (i >= 7 && s.substr(i-7, 7) == "dreamer") i -= 7;
    else break;
  }
  if (i == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    auto ans = "NO";
    for (int i = A; i <= B * A; i += A) {
        int t = i % B;
        if (t == C) ans = "YES";
    }

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

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

int main(){
    int n;  cin>>n;
    int a[n+1];   for(int i=0;i<=n;i++)a[i]=0;
    int minx=101;
    for(int i=1;i<=n;i++){
        int x;  cin>>x;
        for(int j=i;j<=n;j++){
            a[j]+=x;
        }
    }

    int ans=101;

    for(int i=1;i<n;i++){
        if(ans>a[i]/i)ans=a[i]/i;
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<string>
#include<tuple>
#include<algorithm>
#include<iomanip>
#include<math.h>
#include<stdio.h>

using namespace std;

int main(){

    int A, B;
    cin >> A >> B;

    if(A <= 8 & B <= 8)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }

}

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


int main(){
  int n;
   int cnt=0;
  int a[100000];
  int p=0;
  cin>>n;
  rep(i,n){
    cin>>a[i];
    if(a[i]%4==0){a[i]=2;cnt++;}
    else if(a[i]%2==0) a[i]=1;
    else a[i]=0;
    p+=a[i];
  }
  if(cnt>=(n/2) ) cout<<"Yes"<<endl;
  else if(p<n) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;

  return 0;
}

Measured memory_bytes: 640
/*
lakshaygpt28
Lakshay Gupta
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using vll = vector < ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;


#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e3 + 10;

char c[N][N];
ll dp[N][N];
ll h, w;
ll solve(ll i, ll j);

int main() {
    fast_io();
    cin >> h >> w;
    for (ll i = 1; i <= h; i++) {
        for (ll j = 1; j <= w; j++) {
            dp[i][j] = -1;
            cin >> c[i][j];
        }
    }
    cout << solve(1, 1) << "\n";
    return 0;
}

ll solve(ll i, ll j) {
    auto &ans = dp[i][j];
    if (ans != -1) {
        return ans;
    }
    ans = 0;
    if (i > h or j > w or c[i][j] == '#') {
        return ans;
    }
    if (i == h and j == w) {
        ans = 1;
        return ans;
    }
    ans = (solve(i + 1, j) + solve(i, j + 1)) % MOD;
    return ans;
}


Measured memory_bytes: 9216
n = int(input())
s = input()
counted = []
for i in range(1, n):
    c = 0
    counted_char = []
    for j in s[:i]:
        if j in s[i:] and j not in counted_char:
            c += 1
            counted_char.append(j)
    counted.append(c)

print(max(counted))

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main() {
    map<string, int> cnt;
    string s;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        cnt[s]++;
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        cnt[s]--;
    }
    int max = 0;
    map<string, int>::iterator it;
    for (it = cnt.begin(); it != cnt.end(); it++) {
        if (max < it->second) {
            max = it->second;
        }
    }
    cout << max << endl;
    return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
m=10**9+7

def len_max(mat):
    for i in range(len(mat)):
        if len(mat[i])>1:
            return i

n = int(input())
adj_mat =[[] for i in range(n)]



for i in range(n-1):
    a, b = [int(x) for x in input().strip().split()]
    adj_mat[a-1].append(b-1)
    adj_mat[b-1].append(a-1)

root = len_max(adj_mat) or 0


dp=[{'w':None, 'b':None} for i in range(n)]



def cal(parent, node, col):

    nei = adj_mat[node]
    if len(nei)==1:
        if col=='w':
            return 2
        else:
            return 1 
    
    else:
        if dp[node][col]:
            return dp[node][col]
        
        if col=='w':
            sb=1
            sw=1
            for k in nei:
                if k==parent:
                    continue
                sw*=cal(node, k, 'w')%m
                sb*=cal(node, k, 'b')%m
            dp[node][col] = (sb+sw)%m
            return dp[node][col]

        else:
            sw=1
            for k in nei:
                if k==parent:
                    continue
                sw*=cal(node, k, 'w')%m
            dp[node][col] = sw
            return dp[node][col]


ans = cal(None,root,'w')
if n==0:
    print(0)
elif n==1:
    print(2)
elif n==2:
    print(3)
else:
    print(ans%m)


Measured memory_bytes: 136752
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

int K;
vector<vector<int> > G;
vector<int> par;


int ans;
int dfs(int pos){
  int mx = 0;
  for(int to:G[pos]){
    if(to == par[pos]) continue;
    mx = max(mx, dfs(to) + 1);
  }
  
  if(par[pos] != 0 && mx == K-1){ans++; mx = -1;}
  return mx;
}


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin>>N>>K;

  G.resize(N);
  par.resize(N);

  int ofset = 0;
  for(int i=0;i<N;i++){
    int a;
    cin>>a; a--;
    if(i == 0) {
      ofset = (a != 0);
      continue;
    }
    par[i] = a;
    G[i].push_back(a);
    G[a].push_back(i);
  }

  dfs(0);
  cout<<ans + ofset<<endl;
  
  return 0;
}


Measured memory_bytes: 10752
import java.io.*;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long mod = 998244353;
    long inv2 =1;
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        main.solve();
//        out.println(main.solve());
        out.flush();
    }
    void solve() throws IOException {
        char[] ss = sc.next().toCharArray();
        for(int i=0; i<ss.length; i++){
            if(ss[i]=='?') ss[i] = 'D';
        }
        out.println(new String(ss));
    }
}

Measured memory_bytes: 41580
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define inf (1<<29)
#define MAX 57
using namespace std;

bool dp[MAX][MAX][2];
 
int main()
{
  int T;
  while(cin >> T)
    {
      while(T--)
	{
	  rep(i,MAX)rep(j,MAX)rep(l,2)dp[i][j][l] = false;
	  int N;
	  cin >> N;
	  int input[N];
	  rep(i,N) cin >> input[i];
       
	  if(N <= 2)
	    {
	      cout << input[N-1] << endl;
	      continue;
	    }
       
	  int ans = input[N-1];
 
	  REP(cur,1,N-1)
	    {
	      dp[input[cur-1]][input[cur]][cur&1] = true;
	      int R = input[cur+1];
	      rep(L,MAX)
		{
		  rep(M,MAX)
		    {
		      if(!dp[L][M][cur&1])continue;
		      //cout << cur << " cur(" << L << "," << M << "," << R << ")\n";
		      if(M == 0)
			{
			  if(cur+2 < N)
			    {
			      dp[M][R][(cur+1)&1] = true;
			      //cout << cur << " next ( " << M << "," << R << "," << input[cur+2] << ")\n";
			    }
			  else       ans = max(ans,R);
			}
		      else
			{
			  if(cur+2 < N)
			    {
			      dp[M][R][(cur+1)&1] = true;
			      //cout << cur << " next ( " << M << "," << R << "," << input[cur+2] << ")\n";
			      dp[M-1][R+L][(cur+1)&1] = true;
			      //cout << cur << " next ( " << M-1 << "," << R+L << "," << input[cur+2] << ")\n";
			    }
			  else 
			    {
			      ans = max(ans,R+L);
			      //cout << cur << " ans : " << R << "+" << L << "=" << R+L <<  " (" << L << "," << M << "," << R << ")" <<  endl;
			    }
			}
		    }
		}
	      rep(i,MAX)rep(j,MAX)dp[i][j][cur&1] = false;
	    }
	  
	  cout << ans << endl;      
	}
    }
  return 0;
}

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

int A[100005], tree[400005];
map<int, int> M;

void update(int left, int right, int x, int val, int root)
{
    if(left > x || right < x)
        return;
    
    if(left == right)
    {
        tree[root] = val;
        return;
    }

    int mid = (left + right) / 2;

    update(left, mid, x, val, root*2);
    update(mid+1, right, x, val, root*2+1);

    tree[root] = max(tree[root*2], tree[root*2+1]);
}

int query(int left, int right, int L, int R, int root)
{
    if(left > R || right < L)
        return 0;
    
    if(left >= L && right <= R)
        return tree[root];
    
    int mid = (left + right) / 2;

    return max(query(left, mid, L, R, root*2), query(mid+1, right, L, R, root*2+1));
}

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

    int N;
    cin >> N;

    for(int i=1; i<=N; i++)
    {
        cin >> A[i];
        M[ A[i] ];
    }

    int k = 0;

    for(auto &it : M)
        it.second = ++k;
    
    for(int i=1; i<=N; i++)
        A[i] = M[ A[i] ];
    
    int ans = 0;

    for(int i=1; i<=N; i++)
    {
        int curr = query(1, k, A[i], k, 1) + 1;
        update(1, k, A[i], curr, 1);
        ans = max(ans, curr);
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    string s, t;
    cin >> s >> t;
    int n = s.length();
    int m = t.length();
    string str = s + s;
    vector<vector<int>> pos(26);
    for(int i = 0; i < n * 2; ++i){
        pos[str[i] - 'a'].emplace_back(i);
    }
    ll cnt = 0;
    int cur = -1;
    for(int i = 0; i < m; ++i){
        int c = t[i] - 'a';
        if(pos[c].size() == 0){
            cout << -1 << endl;
            return 0;
        }
        int p = upper_bound(pos[c].begin(), pos[c].end(), cur) - pos[c].begin();
        int now = pos[c][p];
        if(now >= n){
            ++cnt;
            now -= n;
        }
        cur = now;
    }
    ll ans = cnt * n + cur + 1;
    cout << ans << endl;
}

Measured memory_bytes: 1872
import java.util.*;
public class Main
{
  public static void main(String[] args)
  {
     Scanner  s= new Scanner(System.in);
    int t=s.nextInt();
     int[] arr= new int[t];
    for(int i=0;i<t;i++)
    {
     arr[i]=s.nextInt();
    }
  //  for(int j=0;j<t;j++)
   // System.out.println(arr[j]);
    int[] dp = new int[t];
    dp[0]=0;
    for(int i=1;i<dp.length;i++)
    {
      int c1=Integer.MAX_VALUE;
      int c2=Integer.MAX_VALUE;
      if((i-1)>=0)
        c1=dp[i-1]+Math.abs(arr[i-1]-arr[i]);
      if((i-2)>=0)
        c2=dp[i-2]+Math.abs(arr[i-2]-arr[i]);
 //     System.out.println(c1+" "+c2+" "+i);
      dp[i]= Math.min(c1,c2);
    }
  //  for(int i=0;i<dp.length;i++)
//    System.out.print(dp[i]+" ");
    System.out.println(dp[dp.length-1]);
  }
}


Measured memory_bytes: 50008
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


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


def MS(): return map(str, input().split())


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


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def make4(initial, L, M, N, O):
    return [[[[initial for i in range(O)]
                for n in range(N)]
                for m in range(M)]
                for l in range(L)]


def make3(initial, L, M, N):
    return [[[initial for n in range(N)]
                for m in range(M)]
                for l in range(L)]


def debug(table, *args):
    ret = []
    for name, val in table.items():
        if val in args:
            ret.append('{}: {}'.format(name, val))
    print(' | '.join(ret), file=sys.stderr)


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    A = LI()
    dp_use = [-IINF] * 3
    dp_not_use = [-IINF] * 3
    dp_not_use[0] = 0

    for i in range(N):
        dp_use_next = [-IINF] * 3
        dp_not_use_next = [-IINF] * 3

        for j in range(3):
            if j - 1 >= 0:
                dp_not_use_next[j] = max(dp_use[j], dp_not_use[j-1])
            else:
                dp_not_use_next[j] = dp_use[j]
            dp_use_next[j] = dp_not_use[j] + A[i]

        # print('dp_use    ', *[a if a > -10**10 else '-IINF' for a in dp_use_next])
        # print('dp_not_use', *[a if a > -10**10 else '-IINF' for a in dp_not_use_next])
        dp_use = dp_use_next
        dp_not_use = dp_not_use_next

    if N % 2 == 0:
        print(max(dp_use[1], dp_not_use[0]))
    else:
        print(max(dp_use[2], dp_not_use[1]))


if __name__ == '__main__':
    main()


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

int gcd(int a, int b) {
  if(b == 0) return a;
  
  if(a < b) {
    return gcd(b, a);
  }
  else return gcd(b, a%b);
}

int main() {
  int k;
  cin >> k;
  int sum = 0;
  for(int i = 1; i <= k; i++) {
    for(int j = 1; j <= k; j++) {
      for(int l = 1; l <= k; l++) {
        sum += gcd(i, gcd(j, l));
      }
    }
  }
  cout << sum << endl;
  return 0;
}
  

Measured memory_bytes: 3604
#include<stdio.h>
	#include<string.h>
	int main()
	{
		int len,m,n,i;
		char a[101];
		while(scanf("%s",&a)!=EOF)
		{
			m=200;
			n=200;
			len=strlen(a);
			for(i=0;i<len;i++)
			{
				if(a[i]=='C')
				{
					if(m==200)
					{
							m=i;
					}
				else
				{
					m=m;
				}
				}
				if(a[i]=='F')
				{
					n=i;
				}
			}
			if(m!=200&&n!=200&&m<n) printf("Yes\n");
			else if(m==200||n==200||m>n) printf("No\n");
		}
	}

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

const long long MAX = 1e18;

int main(){
    int N;
    long long A[100010];
    long long ans = 1;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        if (A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    for (int i = 0; i < N; ++i) {
        if (A[i] > MAX / ans) {
            cout  << -1 << endl;
            return 0;
        }
        else {
            ans *= A[i];
        }
    }

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

Measured memory_bytes: 3944
C = list(int(i) for i in input().split())
A = []
B = []
for i in range(C[0], C[0]+C[2]):
    if i in range(C[0], C[1]+1):
        A.append(i)
for i in range(C[1]-C[2]+1, C[1]+1):
    if i in range(C[0], C[1]+1):
        if i not in A:
            A.append(i)
A.sort
for i in range(len(A)):
    print(A[i])

Measured memory_bytes: 3064
import java.util.Scanner

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

    val n = sc.nextInt()
    val nums = List.fill(n)(sc.nextInt)

    @scala.annotation.tailrec
    def solve(list: List[Int]): Int = list match {
      case List(a) => a
      case _ => {
        val min = list.min
        val nextList = list.map(_ % min).filter(_ > 0)

        solve(min :: nextList)
      }
    }

    println(solve(nums))
  }
}


Measured memory_bytes: 60328
require 'pp'

$stdin.gets.chomp.to_i.times do
  line = $stdin.gets.chomp
  ans = false

  if (m = line.match(/^>'(=+)#(=+)~$/)) then
    if m[1].length == m[2].length then
      puts 'A'
      ans = true
    end
  end

  if (m = line.match(/^>\^(.*?)~~$/)) then
    if (m[1].length > 0 && (m[1].unpack("a2"*(m[1].length/2))).all? {|x| x == "Q="}) then
      puts 'B'
      ans = true
    end
  end

  puts 'NA' if !ans
end

Measured memory_bytes: 6256
from itertools import accumulate


N = int(input())
S = input()
black = [0] * N
white = [0] * N
for i in range(N):
    if S[i] == "#":
        black[i] = 1
    else:
        white[i] = 1
black = list(accumulate(black, initial=0))
white = list(accumulate(white, initial=0))
ans = float("inf")
for i in range(N + 1):
    ans = min(ans, black[i] + white[N] - white[i])
print(ans)


Measured memory_bytes: 26456
#define _USE_MATH_DEFINES
#include <cmath>
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a, b,L=0;
	cin >> a >> b;
	for (int i = 1;i <= b - a;i++) {
		L += i;
	}
	cout << L - b << endl;
	return 0;
}

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

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int k;
  string s;
  cin >> k >> s;

  if (s.size() <= k) {
    cout << s << endl;
  } else {
    cout << s.substr(0, k) + "..." << endl;
  }
}


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

grid = tuple(tuple(map(lambda x: x == '.',input())) for _ in range(H))


dp = [float('inf')]*W
dp[0] = 0
prow = [True]*W
for row in grid:
    ndp = [None]*W
    ndp[0] = dp[0] + int(prow[0] and not row[0])
    for i in range(1,W):
        ndp[i] = min(ndp[i-1]+int(row[i-1] and not row[i]),dp[i]+int(prow[i] and not row[i]))
    prow = row
    dp = ndp

print(dp[-1])

Measured memory_bytes: 42992
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n, k;
	cin >> n >> k;
	
	vector<int> ng(10, 0);
	for(int i = 0; i < k; ++i) {
		int a;
		cin >> a;
		ng[a] = 1;
	}
	
	for(int i = n; i < 100000; ++i) {
		int tmp = i;
		vector<int> digits;
		
		while( tmp ) {
			digits.push_back(tmp % 10);
			tmp /= 10;
		}
		
		bool ok = true;
		for(int j = 0; j < digits.size(); ++j) {
			if( ng[digits[j]] == 1 ) {
				ok = false;
				break;
			}
		}
		
		if( ok && n <= i ) {
			cout << i << endl;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>
int main(){
  int a,s,d,z,x,c,v,b,n,q,w,e;
 
  scanf("%d%d%d",&a,&s,&d);

  if(a>s){
    z=s; x=a; c=d;
  }
  else{
    z=a; x=s; c=d;
  }
  if(z>c){
    v=c; b=x; n=z;
  }
  else{
    v=z; b=x; n=c;
  }
  if(b>n){
    q=v; w=n, e=b;
  }
  else{
    q=v; w=b; e=n;
  }
  printf("%d %d %d\n",q,w,e);
  return 0;
}

Measured memory_bytes: 596
def slove():
    import sys
    input = sys.stdin.readline
    d = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    h, w = list(map(int, input().rstrip('\n').split()))
    for i in range(h):
        s = list(map(str, input().rstrip('\n').split()))
        for j in range(w):
            if s[j] == "snuke":
                print(d[j] + str(i+1))
                exit()


if __name__ == '__main__':
    slove()


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

using namespace std;
using ll = long long;
#define MAX_N 75536
#define MOD 1000000007

int main(){
    string s;
    while(cin >> s){
        deque<char>dq;
        for(int i = 0; i < (int)s.size(); i++){
            dq.push_back(s[i]);
        }
        int rev = 0;
        int q;
        cin >> q;
        while(q--){
            int ti;
            cin >> ti;
            if(ti==1){
                rev++;
            }else{
                int a;
                char ch;
                cin >> a >> ch;
                if( a == 1 ){
                    if( rev%2 == 0 ){
                        dq.push_front(ch);
                    }else{
                        dq.push_back(ch);
                    }
                }else{
                    if( rev%2 == 0 ){
                        dq.push_back(ch);
                    }else{
                        dq.push_front(ch);
                    }
                }
            }
        }
        string ans = "";
        while( !dq.empty() ){
            if( rev%2 == 0 ){
                ans.push_back( dq.front() );
                dq.pop_front();
            }else{
                ans.push_back(dq.back());
                dq.pop_back();
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 1412
#include<stdio.h>
#include<string.h>
int main()
{
    int n=3, c=0, f=0;
    char s[n];
    scanf("%s", s);
    if (strcmp(s,"RRR")==0) printf("3\n");
    else if (strcmp(s,"SSS")==0) printf("0\n");
    else if (strcmp(s,"RRS")==0) printf("2\n");
    else if (strcmp(s,"SRS")==0) printf("1\n");
    else if (strcmp(s,"RSR")==0) printf("1\n");
    else if (strcmp(s,"SSR")==0) printf("1\n");
    else if (strcmp(s,"RSS")==0) printf("1\n");
    else if (strcmp(s,"SRR")==0) printf("2\n");
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main(void)
{
  ll a, b, c, d; cin >> a >> b >> c >> d;
  ll ans = 0;
  ll cd = c / gcd(c, d) * d;
  ans = (b - a + 1) - (b / c - (a-1) / c) - (b / d -(a-1) / d) + (b / cd - (a-1) / cd);
  

  
  cout << ans << endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
data = ''
for i in range(h):
    data += input()

array = list(data)
#print(array)

for i, x in enumerate(array):
    if x == '.':
        continue
    cnt = 0
    # 上の確認
    if not i < w:
        if array[i - w] == '#':
            cnt += 1
    # 下の確認
    if i + w < h * w:
        if array[i + w] == '#':
            cnt += 1
    # 左の確認
    if i % w != 0:
        if array[i - 1] == '#':
            cnt += 1
    # 右の確認
    if i % w != w - 1:
        if array[i + 1] == '#':
            cnt += 1

    if cnt == 0:
        print('No')
        break
else:
    print('Yes')




Measured memory_bytes: 3064
while True:
    n = int(input())
    if n == 0:
        break
    a = [int(x) for x in input().split()]
    ans = 10000000
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if abs(a[i]-a[j])<ans:
                ans = abs(a[i]-a[j])
    print(ans)


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

template <typename T>
class SegTree{
private:
  int n;
  vector<T> dat;
  T query_sub(int a, int b, int k, int l, int r);

public:
  SegTree(int _n);
  void update(int k, T a);
  T query(int a, int b);  // [a,b)
};

template <typename T>
SegTree<T>::SegTree(int _n){
   n = 1;
   while(n < _n) n *= 2;
   dat = vector<T>(2*n-1,0);
}

template <typename T>
void SegTree<T>::update(int k, T a){
  k += n-1;
  dat[k] = a;
  while(k > 0){
    k = (k-1)/2;
    dat[k] = max(dat[2*k+1], dat[2*k+2]);
  }
}

template <typename T>
T SegTree<T>::query_sub(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return 0;
  if(a <= l && r <= b) return dat[k];
  T vl = query_sub(a, b, k*2+1, l, (l+r)/2);
  T vr = query_sub(a, b, k*2+2, (l+r)/2, r);
  return max(vl,vr);
}

template <typename T>
T SegTree<T>::query(int a, int b){
  return query_sub(a, b, 0, 0, n);
}


int main(){
    int n;
    cin >> n;
    SegTree<ll> st(n+1);
    int h[n]; ll a[n];
    rep(i,n) cin >> h[i];
    rep(i,n) cin >> a[i];
    rep(i,n) st.update(h[i],st.query(0,h[i])+a[i]);
    cout << st.query(0,n+1) << endl;
    return 0;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    vector <long long> vect;
    vect.push_back(a+b);vect.push_back(a-b);vect.push_back(a*b);
    sort(vect.begin(),vect.end());
    cout<<vect[2];
    return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, ans, sum, last, cnt = 25000, a[100000],dp[60][10000];
Pll b[100000];
struct Edge { LL to,cost; };
vector<Edge>vec[100000];
string str[3];
bool f;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Seg {
	LL n;
	vector<LL>node, lazy;
	Seg(vector<LL>v) {
		n = 1; while (n < v.size())n *= 2;
		node.resize(n * 2 - 1);
		lazy.resize(n * 2 - 1);
		rep(i, n)node[n + i - 1] = v[i];
		Mfor(i, n - 2)node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
	}
	Seg(LL n_) {
		n = 1; while (n < n_)n *= 2;
		node.resize(n * 2 - 1);
		lazy.resize(n * 2 - 1);
		rep(i, n)node[n + i - 1] = 0;
		Mfor(i, n - 2)node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
	}
	void eval(LL k, LL l, LL r) {
		if (lazy[k] != 0) {
			node[k] += lazy[k];
			if (r - l >= 1) {
				lazy[k * 2 + 1] += lazy[k] / 2;
				lazy[k * 2 + 2] += lazy[k] / 2;
			}
			lazy[k] = 0;
		}
	}
	void add(LL i, LL x, LL a, LL b, LL l, LL r) {
		eval(i, a, b);
		if (b < l || r < a)return;
		if (l <= a&&b <= r) {
			lazy[i] += (b - a + 1)*x;
			eval(i, a, b);
		}
		else {
			add(i * 2 + 1, x, a, (a + b) / 2, l, r);
			add(i * 2 + 2, x, (a + b + 1) / 2, b, l, r);
			node[i] = node[i * 2 + 1] + node[i * 2 + 2];
		}
	}
	LL getsum(LL i, LL a, LL b, LL l, LL r) {
		eval(i, a, b);
		if (b< l || r < a)return 0;
		if (l <= a&&b <= r)return node[i];
		return (getsum(i * 2 + 1, a, (a + b) / 2, l, r)+getsum(i * 2 + 2, (a + b + 1) / 2, b, l, r));
	}
};
int main() {
	cin >> n >> q;
	Seg seg(n);
	rep(i, q) {
		LL x, y, z, w;
		cin >> x;
		if (x == 0) {
			cin >> y >> z >> w;
			seg.add(0, w, 0, seg.n - 1, y - 1, z - 1);
		}
		else {
			cin >> y >> z;
			cout << seg.getsum(0, 0, seg.n - 1, y - 1, z - 1) << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
const int N=2e3+5;
int n,l[N],sum;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<2*n;i++){
        scanf("%d",&l[i]);
    }
    sort(l,l+2*n,greater<int>());
    for(int i=1;i<2*n;i+=2){
        sum+=l[i];
    }
    printf("%d\n",sum);
    return 0;
}


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

int main() {
  int n, m = 0;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++)
    cin >> a.at(i);
  for(int i = 0; i < n - 1; i++)
    for(int j = i + 1; j < n; j++)
      m = max(m, abs(a.at(i) - a.at(j)));
  cout << m << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn
object Main extends App {
  val x = StdIn.readLine.toInt
  val r = math.sqrt(x).toInt
  val ans = if( r == 1) x else
    (2 to r).map { i =>
      val e = for {
        j <- (2 to r)
        e = math.pow(i,j).toInt if(e <= x)
      } yield e
      e.max
    }.max
  println(ans)
}

Measured memory_bytes: 27052
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int k=1;
        while(true){
            int a=sc.nextInt();
            if(a==0) break;
            System.out.printf("Case %d: %d\n",k,a);
            k++;
        }
    }
}


Measured memory_bytes: 66656
def main():
    N = int(input())
    t1, x1, y1 = 0, 0, 0

    for i in range(N):
        t2, x2, y2 = map(int, input().split())
        dt = t2 - t1
        ds = abs(x1 - x2) + abs(y1 - y2)
        if dt - ds >= 0 and (dt - ds) % 2 == 0:
            pass
        else:
            print('No')
            return
    print('Yes')


if __name__ == '__main__':
    main()

Measured memory_bytes: 47576
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner s = new Scanner(System.in);
    int m = s.nextInt();
    int n = s.nextInt();
    int count = 0;
    if(m>=2)
      count+=(m)*(m-1)/2;
    if(n>=2)
      count+=(n)*(n-1)/2;
    System.out.println(count);
  }
}
    

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-

def judege_palindromic(val_str):
    length = len(val_str)
    match = True
    for i in range(length//2):
        if val_str[i] != val_str[length-i-1]:
            match = False
            break

    return match       


A, B = map(int, input().split())

cnt = 0
for i in range(A, B+1, 1):
    if judege_palindromic(str(i)):
        cnt += 1

print(cnt)

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

int sort(const void *a, const void *b);

int main()
{
  int i;
  int h[10];
  for(i=0;i<10;i++)
    {
      scanf("%d",&h[i]);
    }
  qsort(h,10,sizeof(int),sort);
  for(i=0;i<3;i++)
    {
      printf("%d\n", h[i]);
    }
  return 0;
}

int sort(const void *a, const void *b)
{
  return *(int*)b - *(int*)a;
}

Measured memory_bytes: 0
import numpy as np
import itertools as it
n = int(input())
x = []
y = []
for _ in range(n):
    a, b = input().split(' ')
    x.append(int(a))
    y.append(int(b))


def f(xi, xj, yi, yj):
    return np.sqrt((xi - xj)**2 + (yi - yj)**2)


n_l = list(range(n))

l = list(it.permutations(n_l))

count = 0

for i in set(l):
    i = list(i)
    for j in range(n - 1):
        a = i[j]
        b = i[j + 1]
        count += f(x[a], x[b], y[a], y[b])

print(count / len(l))


Measured memory_bytes: 21040
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	vi a(n); cin >> a;
	sort(a.rbegin(), a.rend());
	vi v;
	int t = 2;
	while (1)
	{
		v.push_back(t);
		if (t <= a[0]) t *= 2;
		else break;
	}
	map<int, int> cnt;
	for (auto i : a) cnt[i]++;
	int ans = 0;
	REP(i, n)
	{
		if (cnt[a[i]] == 0) continue;
		for (int j = v.size() - 1; j >= 0; j--)
		{
			int k = v[j] - a[i];
			if (k < 0) break;
			if (a[i] != k)
			{
				if (cnt.count(k) && cnt[k] > 0)
				{
					ans++;
					cnt[k]--;
					cnt[a[i]]--;
				}
			}
			else if (a[i] == k)
			{
				if (cnt.count(k) && cnt[k] > 1)
				{
					ans++;
					cnt[k]--;
					cnt[a[i]]--;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10496
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll W, H, x, y;
  cin >> W >> H >> x >> y;
  int dup = 0;
  if (x*2==W && y*2==H) dup = 1;
  auto ans = W*H/2.0;
  cout << fixed << setprecision(10) << ans;
  cout << " " << dup << endl;
  return 0;
}

Measured memory_bytes: 3220
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}

int main(){
    long long int H,W;
    cin>>H>>W;
    if(H==1||W==1){
        cout<<1<<endl;
        return 0;
    }
    if((H*W)%2==0){
        cout<<(H*W)/2<<endl;
        return 0;
    }else{
        cout<<(W*H)/2+1<<endl;
        return 0;
    }
}

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

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

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

	typedef pair<int, int> point;
	constexpr int dx[] = {0, 1, 0, 1};
	constexpr int dy[] = {0, 0, 1, 1};

	int n;
	cin >> n;

	map<point, int> foxes;
	for(int i = 0; i < n; ++i) {
		int x, y, w;
		cin >> x >> y >> w;
		foxes[point(x, y)] += w;
	}

	int ans = 0;
	for(const auto &e : foxes) {
		const int x = e.first.first;
		const int y = e.first.second;

		for(int cx = x - 1; cx <= x; ++cx) {
			int tmp = 0;
			for(int d = 0; d < 4; ++d) {
				const point p(cx + dx[d], y + dy[d]);
				if(foxes.count(p)) tmp += foxes[p];
			}
			chmax(ans, tmp);
		}
	}

	cout << ans << " / 1" << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 7456
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

int main() {
    ll x, n;
    cin >> x >> n;

    vl p(n);
    rep(i, n) {
        cin >> p[i];
    }

    ll ans = INF;
    ll u = INF;
    exrep(i, 0, 101) {
        bool ok = true;
        rep(j, n) {
            if(p[j] == i) {
                ok = false;
            }
        }
        if(ok) {
            if(abs(i-x) < u) {
                ans = i;
                u = abs(i-x);
            }
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int dp[1000005][2];

int main(){
  string s;
  cin >> s;
  int n = s.size()+1;
  reverse(s.begin(),s.end());
  s += '0';
  rep(i,n+3)rep(j,2)dp[i][j]=INF;
  dp[0][0]=0;
  for(int i=0;i<n;i++)rep(j,2){
    int nd = s[i]-'0';
    if(j==1)nd++;
    rep(d,10){
      if(d>=nd){
        dp[i+1][0]=min(dp[i+1][0],dp[i][j]+d+d-nd);
      }else{
        dp[i+1][1]=min(dp[i+1][1],dp[i][j]+d+d+10-nd);
      }
    }
  }
  cout << dp[n][0] << endl;
}

Measured memory_bytes: 9204
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int[][] A = new int[N][3];
		for(int i = 0; i < N; i++) {
			A[i][0] = s.nextInt();
			A[i][1] = s.nextInt();
			A[i][2] = s.nextInt();
		}
		
		int[][] dp = new int[N][3];
		dp[0][0] = A[0][0];
		dp[0][1] = A[0][1];
		dp[0][2] = A[0][2];
		for(int i = 1; i < N; i++) {
			for(int k = 0; k < 3; k++) {
				dp[i][k] = Math.max(dp[i-1][(k+1)%3], dp[i-1][(k+2)%3]) + A[i][k];
			}
		}
		int result = Math.max(dp[N-1][0], dp[N-1][1]);
		result = Math.max(dp[N-1][2], result);
      	System.out.println(result);
    }
}

Measured memory_bytes: 100560
#include <iostream>
#include <vector>
#include <assert.h>

using namespace std;

#define MOD ((int)1e9+7)

// quadratic matrix class:
template <typename T>
class Matrix2D {
public:
    Matrix2D(int deg) {
        vec.resize(deg);
        for (int i=0; i<deg; i++) {
            vec[i].resize(deg, 0);
            vec[i][i] = 1;
        }
    }

    Matrix2D(vector<vector<T>> v)
    : vec(v) 
    {}

    Matrix2D pow(unsigned long long pow) {
        Matrix2D st = *this;
        return rec_pow(st, pow);
    }

    Matrix2D operator*(const Matrix2D& b) {
        uint N = vec.size();
        assert(vec.size() == b.vec.size());

        vector< vector<T> > ans(N, vector<T>(N));
        for (uint i=0; i<N; i++) {
            for (uint j=0; j<N; j++) {
                T ret = 0;
                for (uint id=0; id<N; id++) {
                    ret += vec[i][id] * b.vec[id][j];
                    ret %= MOD;
                }
                ans[i][j] = ret;
            }
        }

        return Matrix2D(ans);
    }

    // assignment operator
    void operator=(const Matrix2D& other) {
        vec = other.vec;
    }

    T get(uint i, uint j) const {
        return vec[i][j];
    }

    int dim() const {
        return vec.size();
    }

private:
    Matrix2D rec_pow(Matrix2D& M, unsigned long long pow) {
        if (pow == 1) 
            return M;
        
        Matrix2D m = rec_pow(M, pow/2);
        m = m*m;
        if (pow %2 == 1) {
            m = m*M;
        }

        return m;
    }

    vector< vector<T> > vec;
};

template <typename T>
ostream& operator<<(ostream& os, const Matrix2D<T>& m) {
    int N = m.dim();

    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            os << m.get(i,j) << "\t";
        }
        if (i != N-1)
            os << endl;
    }

    return os;
}

int main() {
    int N; cin >> N;
    unsigned long long K; cin >> K;
    vector<vector<unsigned long long>> v(N);    
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            int val; scanf("%d", &val);
            v[i].push_back(val);
        }
    }

    
    Matrix2D<unsigned long long> m(v);

    // cout << m << endl << endl;

    m = m.pow(K);
    
    // cout << m << endl << endl;

    long long ans = 0;
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            ans += m.get(i,j);
            ans %= MOD;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M;
char S[int(1e5 + 5)];
bool able[int(1e5 + 5)];
vector <int> ans;

int main(){
  scanf("%d%d", &N, &M);
  scanf("%s", S);

  int now = N;
  while (now > 0){
    bool flag = false;
    for (int i = M; i >= 1; i--){
      if (now - i < 0) continue;
      if (S[now - i] == '0'){
        flag = true;
        ans.push_back(i);
        now -= i;
        break;
      }
    }
    if (!flag){
      printf("-1\n"); return 0;
    }
  }
  
  printf("%d", ans[ans.size() - 1]);
  for (int i = ans.size() - 2; i >= 0; i--){
    printf(" %d", ans[i]);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 3904
#include <iostream>

using namespace std;

int main(){
  int n;
  long long a=1;
  int b = 1000000007;

  cin >> n;

  for(int i=1;i<=n;++i){
    a *= i;
    if(a >= b){
      a = a%b;
    }
  }
  
  cout << a << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int con,minj,n,i,j,k,l,c=0,a[100];
  scanf("%d",&n);
  for(k = 0;k < n;k++){
    scanf("%d",&a[k]);
  }
  for(i = 0;i < n;i++){
    minj = i;
    for(j = i;j < n;j++){
      if(a[j] < a[minj]){
	minj = j;
      }
    }
    con=a[i];
    a[i]=a[minj];
    a[minj]=con;
    if(a[minj]>a[i])c++;

  }
  for (l = 0; l < n; l++) {
    if(l < n-1){
      printf("%d ",a[l]);
    }
    else if(l==n-1){
      printf("%d\n",a[l]);
    }
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 600