akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace ITP1_11_B {
    class Dice {
        private int[] _dice;

        public int Top {
            get {
                return _dice[0];
            }
        }

        public Dice(int[] dice) {
            _dice = dice;
        }

        public int CheckRight(int top,int front) {
            SetTop(top);
            if (_dice[1] == front)
                return _dice[2];
            string dir = "RRR";
            foreach (var d in dir) {
                Move(d);
                if (_dice[1] == front)
                    return _dice[2];
            }
            return -1;
        }

        private void SetTop(int top) {
            if (_dice[0] == top)
                return;
            string dir = "NNNEEE";
            foreach (var d in dir) {
                Move(d);
                if (_dice[0] == top)
                    return;
            }
        }

        public void Move(string dir) {
            foreach (var d in dir) {
                Move(d);
            }
        }

        public void Move(char dir) {
            switch (dir) {
                case 'E':
                    Replace(0, 3, 5, 2);
                    break;
                case 'W':
                    Replace(0, 2, 5, 3);
                    break;
                case 'N':
                    Replace(0, 1, 5, 4);
                    break;
                case 'S':
                    Replace(0, 4, 5, 1);
                    break;
                case 'R':
                    Replace(1, 2, 4, 3);
                    break;
            }
        }

        private void Replace(int a, int b, int c, int d) {
            int temp = _dice[a];
            _dice[a] = _dice[b];
            _dice[b] = _dice[c];
            _dice[c] = _dice[d];
            _dice[d] = temp;
        }
    }

    class Program {
        static void Main(string[] args) {
            int[] nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = int.Parse(Console.ReadLine());
            Dice dice = new Dice(nums);
            for(int i = 0; i < n; i++) {
                string[] input = Console.ReadLine().Split(' ');
                int top = int.Parse(input[0]);
                int front = int.Parse(input[1]);
                Console.WriteLine(dice.CheckRight(top, front));
            }
        }
    }
}

Measured memory_bytes: 9532
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    string s;
    cin>>s;
    int n=s.size();
    int l=0,r=0,ans=0;
    while(l<n){
        while((s[r]=='A' or s[r]=='C' or s[r]=='T' or s[r]=='G') and r<n){
            ans=max(ans,r-l+1);
            r++;
        }
        r++;
        l=r;
    }
    cout<<ans<<endl;
 return 0;   
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n;
  cin >> n;
  cout << (n+1)/2<<endl;
}


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

int main() {
  ll n; cin >> n;
  ll i = 0;
  ll ans = 1e10;
  while (i*i < n) {
    i++;
    ll cost = 1e10;;
    if (n % i == 0) {
      string a = to_string(i);
      string b = to_string(n/i);
      if (a.size() < b.size()) {
        cost = b.size();
      } else {
        cost = a.size();
      }
    }
    if (cost < ans) ans = cost;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;
int n;
string s;
struct BIT{
    int bit[maxn];
    int query(int x){
        int res = 0;
        for( ; x > 0 ; x &= x - 1)res += bit[x];
        return res;
    }
    void update(int x , int delta){
        for( ; x <= n ; x += x & -x)bit[x] += delta;
    }
}a[26];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> s;
    s = " " + s;
    for(int i = 1 ; i <= n ; ++i){
        a[s[i] - 'a'].update(i,1);
    }
    int q;cin >> q;
    while(q--){
        int type;cin >> type;
        if(type == 1){
            int i;char c;cin >> i >> c;
            a[s[i]-'a'].update(i,-1);
            s[i] = c;
            a[s[i]-'a'].update(i,1);
        }else{
            int res = 0,l,r;cin >> l >> r;
            for(int i = 0 ; i < 26 ; ++i){
                res += (bool)(a[i].query(r)-a[i].query(l-1));
            }
            cout << res << '\n';
        }
    }
}


Measured memory_bytes: 51760
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ws = readLine()!!.split(' ').map { it.toInt() }
    var ans = Int.MAX_VALUE
    for (i in (2 until n)) {
        ans = Math.min(ans, Math.abs(ws.take(i).sum() - ws.takeLast(n - i).sum()))
    }
    println(ans)
}


Measured memory_bytes: 38236
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s, t;
    cin >> s >> t;
    int na = SZ(s);
    int nb = SZ(t);
    sort(ALL(s));
    sort(ALL(t));
    if(s[0] < t.back()){
        cout << "Yes";
        return 0;
    }else if(s[0] == s.back() && t.back() == t[0] && t.back() == s[0]){
        if(na < nb){
            cout << "Yes";
            return 0;
        }else{
            cout << "No";
            return 0;
        }
    }
    cout << "No";
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

using namespace std;

#define int long long

int n, m, k;
int c[3001][3001];
int f[3001][3001][4], g[3001][3001][4];

int gay(int x, int y, int cur)
{
	if (x == n && y == m)
	{
		if (cur < 3)
			return c[x][y];
		return 0;	
	}
	if (g[x][y][cur])
		return f[x][y][cur];
	int cur_ans = 0;
	if (y < m) cur_ans = max(cur_ans, gay(x, y + 1, cur));
	if (y < m && cur < 3) cur_ans = max(cur_ans, gay(x, y + 1, cur + 1) + c[x][y]);
	if (x < n) cur_ans = max(cur_ans, gay(x + 1, y, 0));
	if (x < n && cur < 3) cur_ans = max(cur_ans, gay(x + 1, y, 0) + c[x][y]);
	g[x][y][cur] = 1;
	return f[x][y][cur] = cur_ans;
}

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

	cin >> n >> m >> k;
	for (int i = 1; i <= k; i++)
	{
		int x, y, v;
		cin >> x >> y >> v;
		c[x][y] = v;
	}
	cout << gay(0, 1, 0);
}


Measured memory_bytes: 637308
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define setp(x) setprecision(x)
#define nep(x) next_permutation(x);
using namespace std;
using ull = unsigned long long;
using ll = long long;

int main(){
    ll N;
    cin >> N;
    ll ans = N - 1;
    for(ll i = 2; i * i <= N; i++){
        if(N % i == 0){
            ans = min(ans, i + N / i - 2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, XY):
    tmp = 0
    for x, y in XY:
        tmp += (abs(x) + abs(y)) % 2
    if tmp % N != 0:
        print(-1)
        return
    import math
    m = math.ceil(math.log2(2 * 10 ** 9)) + 1
    d = [2 ** (m - i) for i in range(m)] + [1]
    d += [1] if tmp == 0 else []
    m = len(d)
    w = []
    for xi, yi in XY:
        xx = 0
        yy = 0
        W = ''
        for di in d:
            if abs(xi - xx) >= abs(yi - yy):
                if xx <= xi:
                    xx += di
                    W += 'R'
                else:
                    xx -= di
                    W += 'L'
            else:
                if yy <= yi:
                    yy += di
                    W += 'U'
                else:
                    yy -= di
                    W += 'D'
        w.append(W)
    print(m)
    print(' '.join([str(i) for i in d]))
    [print(wi) for wi in w]


if __name__ == '__main__':
    # S = input()
    N = int(input())
    # N, M = map(int, input().split())
    # A = [int(i) for i in input().split()]
    # B = [int(i) for i in input().split()]
    XY = [[int(i) for i in input().split()] for _ in range(N)]
    solve(N, XY)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


Measured memory_bytes: 9444
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
 
using namespace std;

int i,j,k;
 
int max(int a, int b)
{
    if(a>b) return a;
    else return b;
}
 
int min(int a,int b)
{
    if(a<b) return a;
    else return b;
}

int fast_power(int a,int b)
{
    int res=1;
    while(b>0)
    {
        if(b%2==0)
        {
            b/=2;
            a=(a*a)%mod;
        }
        else
        {
             b/=2;
             res=(res*a)%mod;
            a=(a*a)%mod;
        }
    }
    return res;
}
int palindrone(string s,int l,int r)
{
    int flag=1;
    while(l<r)
    {
        if(s[l]!=s[r])
        {
            flag=0; 
            break;
        }
        l++;
        r--;
    }
    return flag;
}


signed main()
{
    IOS;
    int n,i;
    cin>>n;
    vi v(n),a(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
        a[v[i]-1]++;
    }
    int sum=0;
    for(i=0;i<n;i++) sum+=a[i]*(a[i]-1)/2;
    for(i=0;i<n;i++) cout<<sum-(a[v[i]-1]-1)<<endl;
    return 0;
}

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

using namespace std;

int main (void){
  int n;
  cin >> n;
  cin.ignore();

  int a[n];
  int tmp;

  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a, a + n);

  unsigned short color = 0;
  bool ex[8] = {0};
  int fs = 0;

  for (int i = 0; i < n; i++){
    while (color < 8){
      if(color * 400 <= a[i] && a[i] < (color + 1) * 400){
        ex[color] = true;
        break;
      } else color++;
    }
    if(color == 8){
      fs++;
      continue;
    }
  }

  int nc = 0;
  for (int i = 0; i < 8; i++){
    if(ex[i]) nc++;
  }

  if (nc == 0 && fs != 0) cout << 1 << " " << endl;
  else cout << nc << " " << flush;
  /*
  if(nc + fs >= 8) cout << 8 << endl;
  else cout << nc + fs << endl;
  */
  cout << nc + fs << endl;
  return 0;
}


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

int main() {
  int N, cnt = 0;
  string S;
  cin >> N >> S;
  for (int i = 0; i < 10; i++) {
    char ii = '0' + i;
    for (int j = 0; j < 10; j++) {
      char jj = '0' + j;
      for (int k = 0; k < 10; k++) {
        char kk = '0' + k;
        int flag = 0;
        for (char l : S) {
          if (flag == 0 && l == ii) {
            flag = 1;
            continue;
          }
          if (flag == 1 && l == jj) {
            flag = 2;
            continue;
          }
          if (flag == 2 && l == kk) {
            cnt++;
            break;
          }
        }
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    sort(a.begin(),a.end());
    sort(b.rbegin(),b.rend());
    int al=a.length();
    int bl=b.length();

    if(a<b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
return 0;
}


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

using namespace std;

int main()
{
	map<string, int> days;
	days["SUN"] = 8;
	days["SAT"] = 7;
	days["FRI"] = 6;
	days["THU"] = 5;
	days["WED"] = 4;
	days["TUE"] = 3;
	days["MON"] = 2;
	
	string s;
	cin >> s;
	int num = days[s];
	if (num == 8)
	{
		cout << 7;
	}
	else {
		cout << 8 - num;
	}
	
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char s[200][200];
    int n,l,i,j;
    char a[300];
    while(~scanf("%d%d",&n,&l))
    {
        for(i=0;i<n;i++)
            scanf("%s",s[i]);
        for(i=0;i<n-1;i++)
            for(j=0;j<n-1-i;j++)
                if(strcmp(s[j],s[j+1])>0)
                {
                    strcpy(a,s[j]);
                    strcpy(s[j],s[j+1]);
                    strcpy(s[j+1],a);
                }
        for(i=0;i<n;i++)
            printf("%s",s[i]);
        printf("\n");
    }
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  int k=0;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    if(a%2) k++;
  }
  if(k%2) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;


int main(){
    ll temp,x;
    int A,B,Q;
    cin>>A>>B>>Q;
    vector<ll> s,t;
    s.push_back(-100000000000); t.push_back(-100000000000);
    for(int i=0;i<A;i++){
        cin>>temp;
        s.push_back(temp);
    } 
    for(int i=0;i<B;i++){
        cin>>temp;
        t.push_back(temp);
    } 
    s.push_back(100000000000); t.push_back(100000000000);

    for(int i=0;i<Q;i++){
        cin>>x;
        int nums=lower_bound(s.begin(),s.end(),x)-s.begin(),numt=lower_bound(t.begin(),t.end(),x)-t.begin();
        ll ans=max(s[nums],t[numt])-x;
        ans=min(ans,x-min(s[nums-1],t[numt-1]));

        ans=min(ans,(x-t[numt-1])*2+s[nums]-x);
        ans=min(ans,(x-s[nums-1])*2+t[numt]-x);
        ans=min(ans,(s[nums]-x)*2+x-t[numt-1]);
        ans=min(ans,(t[numt]-x)*2+x-s[nums-1]);
        cout<<ans<<endl;

    }



}


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

int main() {
  int N, K;
  cin >> N >> K;
  int distance = 0;
  vector<int> x(N);
  for(int i =0; i< N; i++){
   cin >> x.at(i);
  }
  for(int i = 0; i< N; i++){
    char c = x.at(i);
    if(2*c < K){
      distance += 2*c;
    }
    else{
      distance += 2*(K-c);
    }
  }
  cout << distance << endl;
  
}


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

int main(){
  int N;
  cin >> N;
  vector<int> num(1e5+5);
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    num[a]++;
  }
  int sum=num[0]+num[1]+num[2];
  int ans=sum;
  for(int i=1;i<1e5;i++){
    sum=sum-num[i-1]+num[i+2];
    ans=max(ans,sum);
  }
  cout << ans << endl;
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int a, b;
int main() {
    std::cin >> a >> b;

    int prev = 1, now = 0;
    for(int i=2; i<=999; ++i) {
        now = prev + i;

        if(now-prev == b-a) {
           std::cout << now - b << std::endl;
           return 0;
        }
        prev = now;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    FOR(i,1,n) {
        int tmp = 0;
        REP(j,n-i) {
            if (s[j] == s[j+i]) {
                tmp++;
                ans = max(ans,tmp);
                if (ans == i) break;
            } else {
                tmp = 0;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"Yes":"No")<<endl;

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: 3624
extern crate core;

use std::io::{self, Read};
use std::collections::HashSet;

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input
        .split("\n")
        .nth(1)
        .unwrap()
        .split_whitespace()
        .map(|x| x.to_string())
        .collect::<HashSet<_>>();
    if list.len() == 3 { "Three" } else { "Four" }.to_string()
}

#[test]
fn test() {
    let tests = vec![
        (
            "6
G W Y P Y W",
            "Four",
        ),
        (
            "9
G W W G P W P G G
",
            "Three",
        ),
        (
            "8
P Y W G Y W Y Y",
            "Four",
        ),
    ];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rb(a,b,c) for(int a=b; a<=c; a++)
#define rl(a,b,c) for(int a=b; a>=c; a--)
#define vbe(v) v.begin()
#define ven(v) v.end()
#define all(v) v.begin(), v.end()
#define ll long long
#define vi vector<int>
#define vf vector<float>
#define vd vector<double>
#define vs vector<string>
#define vl vector<long>
#define PB push_back
#define POB pop_back

using namespace std;
const int INF=1e9, MOD=1e9+7;

int main()
{
  ll a,n;
  string s="APPROVED";
  cin >> n;
  rep(i, n)
  {
    cin >> a;
    if(a%2==0)
    {
      if(a%3!=0 && a%5!=0)
      {
        s="DENIED";
        break;
      }
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h> 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <boost/math/common_factor.hpp>
#include <algorithm>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include<chrono>
 
using namespace std;
//using namespace std::chrono;
 
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define vl int64_t

int main()
{
     ll a,b;
     cin>>a>>b;
     ll prod=a*b;
     //ll hcf=_gcd(a,b);
     //ll final=prod/hcf;
     cout<<boost::math::lcm(a,b);
     
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> memo(100002);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    memo.at(a.at(i) + 1)++;
    memo.at(a.at(i))++;
    memo.at(a.at(i) + 2)++;
  }
  int ans = 0;
  for (int i = 0; i < 100000; i++) {
    ans = max(ans, memo.at(i));
  }
  cout << ans << endl;
}

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

int main(){
    using namespace std;

    constexpr unsigned long N{200000}, register_length{100}, reg(N - register_length);

    unsigned long cnt{0};
    vector<unsigned long> sim(N);
    const auto& cmp = [&cnt, &sim](unsigned long i, unsigned long j, unsigned long k) -> void {
        cout << "< " << i << " " << j << " " << k << endl;
        ++cnt;
        sim[k] = static_cast<unsigned long>(sim[i] < sim[j]);
    };
    const auto& add = [&cnt, &sim](unsigned long i, unsigned long j, unsigned long k) -> void {
        cout << "+ " << i << " " << j << " " << k << endl;
        ++cnt;
        sim[k] = sim[i] + sim[j];
    };
    const auto& bit_and_add = [&cmp, &add](unsigned long i, unsigned long j, unsigned long k) -> void {
        cmp(i, j, reg);
        cmp(j, i, reg + 1);
        add(reg, reg + 1, reg + 1);
        add(i, j, reg);
        cmp(reg + 1, reg, reg);
        add(k, reg, k);
    };
    const auto& binary_mul = [&bit_and_add](unsigned long i, unsigned long i_len, unsigned long j, unsigned long j_len, unsigned long k) -> void {
        for(unsigned long i_ofs{0}; i_ofs < i_len; ++i_ofs)for(unsigned long j_ofs{0}; j_ofs < j_len; ++j_ofs)bit_and_add(i + i_ofs, j + j_ofs, k + i_ofs + j_ofs);
    };
    const auto& bin_to_int = [&add](unsigned long beg, unsigned long len, unsigned long k) -> void {
        for(unsigned long i{len}; i--; ) {
            if(i + 1 != len)add(k, k, k);
            add(beg + i, k, k);
        }
    };
    const auto& zero_clear = [&cmp](unsigned long i) -> void {
        cmp(i, i, i);
    };
    const auto& one_clear = [&cmp](unsigned long i) -> void {
        cmp(2, 1, i);
    };
    const auto& bit_shift = [&add](unsigned long i, unsigned long s) -> void {
        for(unsigned long itr{0}; itr < s; ++itr)add(i, i, i);
    };
    const auto& int_to_bin = [&sim, &bin_to_int, &bit_shift, &zero_clear, &one_clear, &cmp](unsigned long idx, unsigned long i, unsigned long len) -> void {
        one_clear(reg + 2);
        for(unsigned long itr{1}; itr <= len; ++itr){
            zero_clear(reg);
            one_clear(i + len - itr);
            bin_to_int(i + len - itr, itr, reg);
            bit_shift(reg, len - itr);
            cmp(idx, reg, reg + 1);
            cmp(reg + 1, reg + 2, i + len - itr);
        }
    };

    cout << 8431 << endl;
    sim[0] = 100;
    sim[1] = 1987;
    int_to_bin(0, 100, 30);
    int_to_bin(1, 200, 30);
    binary_mul(100, 30, 200, 30, 300);
    bin_to_int(300, 60, 2);
    cerr << sim[2] << " : " << cnt << endl;
    return 0;
}

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

int main(void){
	int n;
  	cin >> n;
  	vector<int> d(n);
  	rep(i,n) cin >> d[i];
  	int ans = 0;
  	rep(j,n) rep(i,j){
    	ans += d[i]*d[j];
    }
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, 0);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ans[a]++;
    ans[b]++;
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
}


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

using namespace std;
using LL = long long;

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

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

	int x = 1, cnt = 0;
	while (x < b) {
		x = x - 1 + a;
		cnt ++;
	}
	cout << cnt << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n + 2);
	for (int i = 1; i <= n; i++) cin >> a[i];
	int s = 0;
	rep(i, n + 1) s += abs(a[i + 1] - a[i]);
	rep(i, n) {
		int t = abs(a[i + 2] - a[i + 1]) + abs(a[i + 1] - a[i]);
		int u = abs(a[i + 2] - a[i]);
		cout << s - t + u << endl;
	}
	return 0;
}


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

int main() {
  long int a, b, k;
  cin >> a >> b >> k;
  long int tmp = 0;
  long int new_a = max(tmp, a - k);
  b = max(tmp, b - (k - (a - new_a)));
  cout << new_a << " " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<double, string> P;

vector<pair<double, string> > v;

bool comp(P lhs, P rhs){
	if(lhs.first != rhs.first) return lhs.first > rhs.first;
	return lhs.second < rhs.second;
}

int main(){
while(1){	//strt
	int n;
	cin >> n;
	if(n == 0) break;
	for(int i = 0; i < n; i++){
		string l;
		int a, b, c, d, e, f, s, m, p;
		cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
		double T = a + b + c + m * (d + e);
		double money = m * f * s - p;
		//小数点以下を使用したいので倍した
		double Er = money / T;

		v.push_back(make_pair(Er, l));
	}

	sort(v.begin(), v.end(), comp);

	for(int i = 0; i < n; i++){
		cout << v[i].second << endl;
	}
	cout << "#" << endl;
	v.clear();
}//end
	return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define very_slow       ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define inf             1e18
#define MAX             1e9
#define MIN            -1e9
#define no_of_test(x)   int x; cin>>x; while(x--)
const double pi=3.14159265359;
const int mod = 1e9 + 6;
//Actual Code Is At The Top
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}
int nodes,edges;
vector<int>adj[100001];
int vis[100001];
void dfs(int node)
{
    if(vis[node]) return;
    vis[node]=1;
    for(auto child:adj[node])
    {
        dfs(child);
    }
}
int32_t main()
{   
	very_slow
//	no_of_test(x)
	{  
	   int n;
       cin>>n;
       while(n--)
       {
           cout<<"ACL";
       }
       cout<<'\n';
	}
	return 0;
}

Measured memory_bytes: 5824
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <algorithm>
#include <map>

using namespace std;

int main(){
    string s;
    cin >> s;
    int cnt = 0, ans = 0;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'T' || s[i] == 'G') cnt++;
        else cnt = 0;
        ans = max(cnt, ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import heapify,heappop,heappush
import sys
read=sys.stdin.readline
class mset:
    def __init__(self):
        self.p,self.q=[],[]
        heapify(self.p);heapify(self.q)
    def add(self,a):
        heappush(self.p,a)
    def delete(self,a):
            heappush(self.q,a)
    def minimum(self):
        while self.q and self.p[0]==self.q[0]:
            heappop(self.p);heappop(self.q)
        return self.p[0] if self.p else None

N,Q=map(int,read().split())
event=[]
for i in range(N):
    S,T,X=map(int,read().split())
    event.append((1,S-X,X))
    event.append((0,T-X,X))

s=mset()
now=0
for i in range(Q):
    D=int(read())
    event.append((2,D,0))
event.sort(key=lambda x:(x[1],x[0]))

for c,t,w in event:
    if c==0:
        s.delete(w)
    elif c==1:
        s.add(w)
    else:
        m=s.minimum()
        print(-1 if m==None else m)

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

#define ll long long int
#define endl '\n'
const long long inf=1e18;
#define mod 1000000007
char ar[1005][1005];
ll dp[1005][1005];


void testCase()
{
   // ll t; cin>>t; while(t--)
    {
        ll n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            cin>>ar[i][j];
        }

        dp[1][1]=1;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(ar[i][j]=='#')
                {
                    dp[i][j]=0;
                    continue;
                }
                if(i>1)
                dp[i][j]+=dp[i-1][j];
                dp[i][j]%=mod;
                if(j>1)
                dp[i][j]+=dp[i][j-1];
                dp[i][j]%=mod;
            }
        }
        cout<<dp[n][m]<<endl;

    } 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    testCase();
    return 0;
}

Measured memory_bytes: 12456
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		while (true)
		{
			int n = sc.nextInt();
			if (n == 0) break;
			
			int num[] = new int[n];
			
			for (int i = 0; i < n; i++)
			{
				num[i] = sc.nextInt();
			}
			int max = Integer.MIN_VALUE;
			for (int i = 0; i < n; i++)
			{
				int sum = 0;
				for (int j = i; j < n; j++)
				{
					sum += num[j];
					max = Math.max(sum, max);
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
int main(void){
	int n;
	scanf("%d", &n);
	int a[n];
	for(int i = 0; i < n; i++){
		scanf("%d", a+i);
	}
	int max = 0;
	int min = 114514;
	for(int i = 0; i < n; i++){
		if(a[i] < min){
			min = a[i];
		}
		if(a[i] > max){
			max = a[i];
		}
	}
	printf("%d\n", max-min);
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
S = input()
sum = 0
for i in range(len(S)):
  if i % 2 == 1:
    if S[i] == "R":
      sum += 1
  if i % 2 == 0:
    if S[i] == "L":
      sum += 1

if sum >= 1:
  print("No")
else:
  print("Yes")


Measured memory_bytes: 2940
#include<stdio.h>
int main()
{
  int a,b;
  
  scanf("%d %d",&a,&b);
  
  if(a<6){
    b=0; 
  }
  else if(5<a&&a<13){
    b=b/2;
  }
  else{
  }
  
  printf("%d",b);
  
  return 0;
}

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

int maxi(int a, int b){
    return (a>b) ? a : b;
}


int main(){

    int n;
    int a, b, c;
    int f1, f2, f3, g1, g2, g3;

    cin >> n;
    cin >> a >> b >> c;
    f1 = a;
    f2 = b;
    f3 = c;

    for(int i = 1; i < n; i++){
        cin >> a >> b >> c;
        g1 = f1;
        g2 = f2;
        g3 = f3;
        f1 = a + maxi(g2,g3);
        f2 = b + maxi(g1, g3);
        f3 = c + maxi(g1, g2);
    }

    cout << maxi(maxi(f1, f2), f3);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin >> s >> t;
	int n=s.size();
	int m=t.size();
	vector<vector<int>>lcs(n+1,vector<int>(m+1,0));
	for(int i=1;i<=n;i++){
	for(int j=1;j<=m;j++){
	if(s[i-1]==t[j-1])lcs[i][j]=lcs[i-1][j-1]+1;
	else lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
	//cout << lcs[i][j] << " ";
	}
	//cout << endl;
	}
	
	string ans;
	int i=n,j=m;
	while(lcs[i][j]!=0){
		
    if(lcs[i][j]!=max(lcs[i-1][j],lcs[i][j-1])){
    ans.push_back(s[i-1]);
    
    i--;j--;
    }
    else{
    if(lcs[i][j]==lcs[i-1][j])i--;
    else j--;
    }
    
	}
	reverse(ans.begin(),ans.end());
	cout << ans;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
long long power(long long x,long long y)
{
    long long res=1;
    x = x%mod;
    while(y>0)
    {
        if(y&1)
            res = (res*x)%mod;
        y=y>>1;
        x=(x*x)%mod;
    }
    return res;
}
int main()
{
    long long t=1,n,i,a,b,c,d;
    //cin>>t;
    while(t--)
    {
        cin>>n;
        a=0;
        if(n>1)
            a=(power(10,n)-((2*power(9,n))%mod)+power(8,n)+mod)%mod;
        cout<<a<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3648
N,M = map(int,input().split())
A = list(map(int,input().split()))

import heapq
for i in range(N):
    A[i] = -A[i]
    
heapq.heapify(A)

while M > 0:
    tmp = -heapq.heappop(A)
    tmp = tmp//2
    M -= 1
    heapq.heappush(A,-tmp)
    
print(-sum(A))

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

const int MAXNUM = 300000;

bool prime[MAXNUM];

void eratos()
{
    prime[0] = prime[1] = false;

    for(int i=2; i<MAXNUM; i++)
	prime[i]=true;

    for(int i=2; i*i<MAXNUM; i++){
	if(prime[i]){
	    for(int j=i*i; j<MAXNUM;  j+=i)
		prime[j] = false;
	}
    }
}


int main()
{
  eratos();
  
    int N;
    while(cin >> N, N){
	int res = 0;

	for(int i=N+1; i<=2*N; i++)
	    if(prime[i]) res++;

	cout << res << endl;
    }
    
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  int N,T;
  cin>>N>>T;
  vector<int> c;
  for(int i=0;i<N;i++){
    int t,x;
    cin>>x>>t;
    if(t<=T){
      c.push_back(x);
    }
  }
  if(c.size()==0){
    cout<<"TLE"<<endl;
  }else{
    sort(c.begin(),c.end());
    cout<<c.at(0)<<endl;
  }
}


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

int main() {
  string s;
  cin >> s;
  
  int count = 0;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < s.size(); j++) {
      if (s.at(i) == s.at(j)) {
        count++;
      }
    }
  }
  if (count > s.size()) {
    cout << "no" << endl;
  }
  else {
    cout << "yes" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];
    rep(X, 101)rep(Y, 101){
        int H = -1;
        rep(i, n){
            if(h[i] > 0){
                H = h[i] + abs(X - x[i]) + abs(Y - y[i]);
                break;
            }
        }
        bool f = 1;
        rep(i, n){
            if(h[i] != max(H - abs(X - x[i]) - abs(Y - y[i]), 0)){
                f = 0;
                break;
            }
        }
        if(f){
            cout << X <<" "<< Y <<" "<< H << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define forit(it, st) for(auto it : st)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);

void solve(){
	ll a, b;
	cin >> a >> b;
	cout << a / __gcd(a, b) * b;
}
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}


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

using namespace std;
typedef long long ll;
const int N = 5050;

int n, k;
ll p[N], pp[N][35], val[N][35], Max[N][35], c[N];
ll ans = -0x3f3f3f3f3f3f3f3f;

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 1;i <= n; ++i) scanf("%lld", &p[i]);
	for(int i = 1;i <= n; ++i) scanf("%lld", &c[i]);
	for(int i = 1;i <= n; ++i) Max[i][0] = val[i][0] = c[p[i]], pp[i][0] = p[i];
	for(int j = 1;j < 32; ++j)
		for(int i = 1;i <= n; ++i)
			pp[i][j] = pp[pp[i][j - 1]][j - 1],
			val[i][j] = val[i][j - 1] + val[pp[i][j - 1]][j - 1],
			Max[i][j] = max(Max[i][j - 1], val[i][j - 1] + Max[pp[i][j - 1]][j - 1]);
	for(int i = 1;i <= n; ++i) {
		ll K = k, P = i, V = 0, A = -0x3f3f3f3f3f3f3f3f;
		for(int j = 30; j >= 0; --j) {
			if(K & (1 << j)) {
				A = max(A, V + Max[P][j]);
				V += val[P][j];
				P = pp[P][j];
			}
		}
		// cout << " --- " << i << " " << A << endl;
		ans = max(ans, A);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7956
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;

ll n;
ll x[100005];
ll r[100005];
ll g = 0;

int cmp(const ll *, const ll *);
ll gcd(ll x, ll y);

int main()
{
    
    scanf("%lld %lld", &n, &x[0]);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &x[i]);
    }

    qsort(x, n + 1, sizeof(ll), (int (*)(const void *, const void *))cmp);

    for (int i = 0; i < n; i++) {
        r[i] = labs(x[i + 1] - x[i]);
    }

    for (int i = 0; i < n; i++) {
        g = gcd(g, r[i]);
    }

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

    return 0;
}

int cmp(const ll *x, const ll *y)
{
    if (*x > *y) {
        return 1;
    }
    else if (*x == *y) {
        return 0;
    }
    else {
        return -1;
    }
}

ll gcd(ll x, ll y)
{
    if (x < y) {
        ll tmp = x;
        x = y;
        y = tmp;
    }

    while (y) {
        ll r = x % y;
        x = y;
        y = r;
    }

    return x;
}


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;

#define INF 10000000

int H, W;
int M[100][100];
int dp[100][100];

bool check(int r, int c)
{
    return r >= 0 && r < H && c >= 0 && c < W;
}

int ans(int BL, int WH)
{
    for(int r = 0;r < H;r++)
    {
        for(int c = 0;c < W;c++)
        {
            dp[r][c] = INF;
        }
    }
    dp[0][0] = (M[0][0] == BL) ? 1 : 0;
    for(int r = 0;r < H;r++)
    { 
        for(int c = 0;c < W;c++)
        {
            if(check(r-1, c))
            {
                int add = (M[r-1][c] == WH &&  M[r][c] == BL) ? 1 : 0;
                dp[r][c] = min(dp[r][c], dp[r-1][c] + add);
            }
            if(check(r, c-1))
            {
                int add = (M[r][c-1] == WH &&  M[r][c] == BL) ? 1 : 0;
                dp[r][c] = min(dp[r][c], dp[r][c-1] + add);
            }
        }
    }

    return dp[H-1][W-1];
}

int main()
{
    cin >> H >> W;
    for(int r = 0;r < H;r++)
    {
        string s;
        cin >> s;

        for(int c = 0;c < W;c++)
        {
            if(s[c] == '#')
            {
                M[r][c] = 0;
            }
            else
            {
                M[r][c] = 1;
            }
        }
    }

    int ans1 = ans(0, 1);
    int ans2 = ans(1, 0);
    int ans = min(ans1, ans2+1);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1016
#include<stdio.h>
#include<string.h>
int flag[20][20];//?????°?????????0
char map[20][21];//y:x
int count;
int H,W;
void search(int nx,int ny);
main(){
    scanf("%d%d",&W,&H);
    while(H){
        memset(flag,0,sizeof(flag));
        memset(map,0,sizeof(map));
        for(int i = 0;i < H;i++){
            scanf("%s",map[i]);
        }
        for(int i = 0;i < H;i++){
            for(int j = 0;j < W;j++){
                if(map[i][j] == '@'){
                    count = 0;
                    search(j,i);
                    printf("%d\n",count);
                }
            }
        }
        scanf("%d%d",&W,&H);
    }
}
void search(int nx,int ny){
    if(nx<0 || ny<0 || nx>W-1 || ny>H-1){
        return;
    }
    if(map[ny][nx] == '#'){
        return;
    }
    if(flag[ny][nx] == 0){
        flag[ny][nx]++;
        count++;
        search(nx+1,ny);
        search(nx-1,ny);
        search(nx,ny+1);
        search(nx,ny-1);
    }
}

Measured memory_bytes: 2736
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    while(true) {
        int M = readln.chomp.to!int;
        if (M==0) break;
        int n = readln.chomp.to!int;
        int[] d = new int[n+2];
        foreach(i; 0..n) d[i+1] = readln.chomp.to!int;
        bool[][] edges = new bool[][](d.length, d.length);
        bool[][] edges_reverse = new bool[][](d.length, d.length);
        foreach(i; 0..d.length) {
            foreach(j; 1..M+1) {
                int k = min(d.length-1, i+j).to!int;
                k += d[k];
                k = max(0, min(d.length-1, k));
                edges[i][k] = true;
                edges_reverse[k][i] = true;
            }
        }

        bool[] flg1 = new bool[d.length];
        flg1[0] = true;
        auto list = DList!(int)(0);
        while(!list.empty) {
            int id = list.front;
            list.removeFront;
            foreach(i, e; edges[id]) {
                if (e && !flg1[i]) {
                    flg1[i] = true;
                    list.insertBack(i.to!int);
                }
            }
        }
        bool[] flg2 = new bool[d.length];
        flg2[$-1] = true;
        list.insertBack(d.length.to!int-1);
        while(!list.empty) {
            int id = list.front;
            list.removeFront;
            foreach(i, e; edges_reverse[id]) {
                if (e && !flg2[i]) {
                    flg2[i] = true;
                    list.insertBack(i.to!int);
                }
            }
        }

        foreach(i; 0..d.length) {
            if (flg1[i] && !flg2[i]) {
                writeln("NG");
                break;
            }
            if (i == d.length-1) {
                writeln("OK");
            }
        }
    }
}

Measured memory_bytes: 3300
import math
N=int(input())
zahyo=[None]*N
for i in range(N):
    zahyo[i]= list(map(int,input().split()))
lensum=0
for i in range(N):
    j=i+1
    while j<N:
        lensum+=math.sqrt((zahyo[i][0]-zahyo[j][0])**2+(zahyo[i][1]-zahyo[j][1])**2)
        j+=1
print(lensum*2/N)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!

int main(void){
    ll a0, a1, N, x, ans=0;
    scanf("%lld %lld", &N, &x);
    rep(i, N) {
        scanf("%lld", &a1);
        if(i){
            if(a0>x) {
                ans += a0-x;
                a0 = x;
            }
            if(a0+a1>x) {
                ans += a0+a1 - x;
                a1  -= a0+a1 - x;
            }
        }
        a0 = a1;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128