akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
#define N 100005


int main(){
 
 ll a,b;
 cin>>a>>b;
 ll ans = -1;
 for(ll i=1;i<=2000;i++)
 {
       double first = (double) (0.08*i);
       double second = (double) (0.10*i);

       ll f = (ll) first;
       ll s = (ll) second;
       if(f==a and s==b) 
       {
       	 cout<<i<<endl;
       	 return 0;

       }
 }

 cout<<ans<<endl;
 return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

#define F first
#define S second
#define MAX 1000003
using namespace std;

typedef long long ll;
const long long  mod = 1000000007;

long long  prime[MAX];
map<long long , long long > max_map;

// Function to return a^n
long long  power(long long  a, long long  n)
{
    if (n == 0)
        return 1;
    long long  p = power(a, n / 2) % mod;
    p = (p * p) % mod;
    if (n & 1)
        p = (p * a) % mod;
    return p;
}

long long power2(long long x,long long n,long long M){
//(x^n)%M
long long result=1;

    while(n){
        if(n%2)
            result=(result*x)%M;
        x=(x*x)%M;
        n/=2;
    }
    return result;
}

long long inverseMod(long long x,long long M){

return power2(x,M-2,M);
}

// Function to find the smallest prime factors
// of numbers upto MAX
void sieve()
{
    prime[0] = prime[1] = 1;
    for (long long  i = 2; i < MAX; i++) {
        if (prime[i] == 0) {
            for (long long  j = i * 2; j < MAX; j += i) {
                if (prime[j] == 0) {
                    prime[j] = i;
                }
            }
            prime[i] = i;
        }
    }
}

// Function to return the LCM modulo M
ll lcmModuloM(const long long * ar, long long  n)
{

    for (long long  i = 0; i < n; i++) {
        long long  num = ar[i];
       map<long long , long long > temp;

        // Temp stores mapping of prime factor to
        // its power for the current element
        while (num > 1) {

            // Factor is the smallest prime factor of num
            long long  factor = prime[num];

            // Increase count of factor in temp
            temp[factor]++;

            // Reduce num by its prime factor
            num /= factor;
        }

        for (auto it : temp) {

            // Store the highest power of every prime
            // found till now in a new map max_map
            max_map[it.first] = max(max_map[it.first], it.second);
        }
    }

    ll ans = 1;

    for (auto it : max_map) {

        // LCM is product of primes to their highest powers modulo M
        ans = (ans * power(it.F, it.S)) % mod;
    }

    return ans;
}

int   main() {
    fast
    sieve();
    long long  n;
    cin>>n;

    long long arr[10002];
    for(long long  i=0;i<n;i++){
        cin>>arr[i];

    }

    //long long  n = sizeof(arr) / sizeof(arr[0]);
    long long lcm=lcmModuloM(arr, n);

    long long ans=0;

    for(long long  i=0;i<n;i++){

        ans=(ans%mod+(lcm*inverseMod(arr[i],mod)))%mod;

    }

    cout<<ans;






	return 0;
}


Measured memory_bytes: 8832
N = int(input())
S = list(map(int, list(input())))

counter = 0
for a in range(10):
    try:
        a_index = S.index(a)
        S_ = S[a_index + 1:]
    except ValueError:
        continue
    for b in range(10):
        try:
            b_index = S_.index(b)
            S__ = set(S_[b_index + 1:])
            counter += len(S__)
        except ValueError:
            continue
print(counter)


Measured memory_bytes: 3976
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int retrnd(int n){
     std::random_device rnd;
     std::mt19937 mt(rnd());
      std::uniform_int_distribution<> rand100(0, n);
      return rand100(mt);
}


int main(){
    SCIN(str);
    CIN(x);CIN(y);
    queue<int> vec;
    int n= 0;
    REP(a,str.size()){
        if(str.at(a)=='T'){
            vec.push(n);
      //      cout<<n<<endl;
            n =0;
        }else{
        n++;
        }
    }
    //cout<<n<<endl;
    S s1,s2;
    vec.push(n);
    s1.insert(vec.front());
    s2.insert(0);
    vec.pop();
    for(int a = 0;!vec.empty();a++){
        int ins = vec.front();
        if(a%2==0){
            S q1;
            FOREACH(b,s2){
                q1.insert(b+ins);
                q1.insert(b-ins);
            }
            s2 = q1;
        }else{
            S q2;
            FOREACH(b,s1){
                q2.insert(b+ins);
                q2.insert(b-ins);
            }
            s1 = q2;
        }
        vec.pop();
    }
    if(s1.find(x)!=s1.end()&&s2.find(y)!=s2.end()){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int N = 100005;
ll n, C, x[N], v[N], pre[N], ans, p, q, ans1, ans2;
ll a[N], b[N], L[N], R[N];

int main() {
    scanf("%lld%lld", &n, &C);
    // 1
    for (int i = 1; i <= n; i++) {
        scanf("%lld%lld", &x[i], &v[i]);
        pre[i] = pre[i - 1] + v[i];
    }
    for (int i = 1; i <= n; i++) {
        ll tmp = pre[i] - x[i];
        a[i] = tmp;
        ans1 = max(ans1, tmp);
    }
    ans = max(ans, ans1);

    // 2
    for (int i = 1; i <= n; i++) pre[i] = v[i];
    for (int i = n; i >= 1; i--) pre[i] += pre[i + 1];
    for (int i = n; i >= 1; i--) {
        ll tmp = pre[i] - (C - x[i]);
        b[i] = tmp;
        ans2 = max(ans2, tmp);
    }
    ans = max(ans, ans2);

    // 3
    for (int i = 1; i <= n; i++) {
        L[i] = max(L[i - 1], a[i] - x[i]);
    }
    for (int i = n; i >= 1; i--) {
        R[i] = max(R[i + 1], b[i]);
    }
    for (int i = 1; i <= n; i++)
        ans = max(ans, L[i] + R[i + 1]);

    // 4
    memset(L, 0, sizeof(L));
    memset(R, 0, sizeof(R));
    for (int i = 1; i <= n; i++) {
        L[i] = max(L[i - 1], a[i]);
    }
    for (int i = n; i >= 1; i--) {
        R[i] = max(R[i + 1], b[i] - (C - x[i]));
    }
    for (int i = 1; i <= n; i++)
        ans = max(ans, L[i] + R[i + 1]);


    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

using ll=long long;

ll N,X,M;

ll dp[100001];
ll idx[100001];

int main() {
    cin >> N >> X >> M;
    if(N < 1000001)
    {
        ll sum = X;
        for(ll i = 1; i < N; ++i)
        {
            (X*=X)%=M;
            sum+=X;
        }
        std::cout << sum << std::endl;
        return 0;
    }
    std::fill(idx,idx+100001,-1);
    dp[0] = X;
    idx[X] = 0;
    ll loopIdx, loopSz;
    for(ll i = 1; i < N; ++i)
    {
        (X*=X)%=M;
        dp[i] = dp[i-1]+X;
        if(idx[X]!=-1)
        {
            //loop
            loopIdx = idx[X];
            loopSz = i - loopIdx;
            break;
        }
        idx[X] = i;
    }
    ll sum = loopIdx==0?0:dp[loopIdx-1];
    N-=loopIdx;
    sum += (N/loopSz)*(dp[loopSz+loopIdx-1] - (loopIdx==0?0:dp[loopIdx-1]));
    N = (N-(N/loopSz)*loopSz);
    if(N)sum += dp[loopIdx+N-1]-(loopIdx==0?0:dp[loopIdx-1]);
    std::cout << sum << std::endl;
}

Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)
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; }

int main() {
  string s;
  cin >> s;
  ll n = s.size();
  
  rep(i, n){
    if(i%2 == 0){//奇数番目
      if(s.at(i) != 'R' && s.at(i) != 'U' && s.at(i) != 'D'){
        cout << "No" << endl;
        return 0;
      }
    }
    if(i%2 == 1){//偶数番目
      if(s.at(i) != 'L' && s.at(i) != 'U' && s.at(i) != 'D'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int N,H[5];
  cin >> N;
  rep(i,5) cin >> H[i];
  sort(H,H+5);
  cout << (N+H[0]-1)/H[0]+4 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,i,j,k,l;
    scanf("%lld",&n);
   m=n/100;
   j=n%100;
   k=j%5;
   l=j/5;
   if(k)
    l++;
    if(l>m)
        printf("0");
    else
        printf("1");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int A, B, C; cin >> A >> B >> C;
  cout << max(0, C - (A - B)) << endl;
  return 0;
}

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

const int maxn = 1e5 + 5,inf = 0x3f3f3f3f;
int A,B,M,ans,mina,minb;
int a[maxn],b[maxn];

int main()
{
    while(scanf("%d%d%d",&A,&B,&M)==3){
        ans = mina = minb = inf;
        for(int i=1;i<=A;i++){
            scanf("%d",&a[i]);
            mina = min(mina,a[i]);
        }
        for(int i=1;i<=B;i++){
            scanf("%d",&b[i]);
            minb = min(minb,b[i]);
        }
        for(int i=1;i<=M;i++){
            int x,y,c;
            scanf("%d%d%d",&x,&y,&c);
            ans = min(ans,a[x]+b[y]-c);
        }
        printf("%d\n",min(ans,mina+minb));
    }
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

const int inf = 1<<21;
const int MAX_V = 11111*4;

struct edge {
  int to,cap,rev;
};
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int f,int t,int cap)
{
  G[f].push_back((edge){t,cap,(int)G[t].size()});
  G[t].push_back((edge){f,0,(int)G[f].size()-1});
}

 void bfs(int s)
{
  memset(level,-1,sizeof(level));
  queue<int> q;
  level[s] = 0;
  q.push(s);
  while( !q.empty() ) {
    int v = q.front(); q.pop();
    for( int i = 0; i < int(G[v].size()); i++ ) {
      edge& e = G[v][i];
      if( e.cap > 0 && level[e.to] < 0 ) {
        level[e.to] = level[v]+1;
        q.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f)
{
  if( v == t ) return f;
  for( int &i = iter[v]; i < int(G[v].size()); i++ ) {
    edge& e = G[v][i];
    if( e.cap > 0 && level[v] < level[e.to] ) {
      int d  = dfs(e.to,t,min(f,e.cap));
      if( d > 0 ) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t)
{
  int flow = 0;
  for(;;) {
    bfs(s);
    if( level[t] < 0 ) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while( (f = dfs(s,t,inf)) > 0 ) {
      flow += f;
    }
  }
}

int h, w;
char g[111][111];

int main(void) {
  scanf("%d%d", &h, &w);
  memset(g, '.', sizeof(g));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      scanf(" %c", g[i]+j);
      if (g[i][j] == 'X' &&
          (i == 1 || i == h || j == 1 || j == w)) {
        puts("-1");
        return 0;
      }
    }
  }

#define I(x, y, st) (((y)*w+(x))*2+(st))
  int dx[] = {0,1,0,-1};
  int dy[] = {1,0,-1,0};

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (g[i][j] == 'X') {
        add_edge(I(j, i, 0), I(j, i, 1), 111111);
      } else {
        add_edge(I(j, i, 0), I(j, i, 1), 1);
      }
      for (int k = 0; k < 4; k++) {
        add_edge(I(j, i, 1), I(j+dx[k], i+dy[k], 0), 1);
      }
    }
  }

  for (int i = 1; i <= h; i++) {
    add_edge(MAX_V-2, I(1, i, 0), 111111);
    add_edge(MAX_V-2, I(w, i, 0), 111111);
  }
  for (int i = 1; i <= w; i++) {
    add_edge(MAX_V-2, I(i, 1, 0), 111111);
    add_edge(MAX_V-2, I(i, h, 0), 111111);
  }
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (g[i][j] == 'X') {
        add_edge(I(j, i, 1), MAX_V-1, 111111);
      }
    }
  }

  int res = max_flow(MAX_V-2, MAX_V-1);
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 3840
/*
  AtCoder Beginner Contest 093
  B - Small and Large Intergers
*/

#include<iostream>
using namespace std;

int A, B, K;

int main() {
  scanf("%d%d%d", &A, &B, &K);
  int AK = A + K - 1, BK = B - K + 1;

  if (AK >= BK) {
    for (int i = A; i <= B; ++i) printf("%d\n", i);
  }
  else {
    for (int i = A; i <= AK; ++i) printf("%d\n", i);
    for (int i = BK; i <= B; ++i) printf("%d\n", i);
  }

  return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int inf = 1e15;
const int mod = 1e9 + 7;

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int a, b, d;
    while (cin >> a >> b >> d, a) {
        int opt_x = -1, opt_y = -1;
        int ma_xy = inf, ma_axby = inf;
        rep(x, 50001) {
            if ((a * x + d) % b == 0) {
                int y = (a * x + d) / b;
                if (x + y < ma_xy || (x + y == ma_xy && a * x + b * y < ma_axby)) {
                    opt_x = x, opt_y = y;
                    ma_xy = x + y;
                    ma_axby = a * x + b * y;
                }
            }
            if ((a * x - d) % b == 0) {
                int y = abs(a * x - d) / b;
                if (x + y < ma_xy || (x + y == ma_xy && a * x + b * y < ma_axby)) {
                    opt_x = x, opt_y = y;
                    ma_xy = x + y;
                    ma_axby = a * x + b * y;
                }
            }
        }

        cout << opt_x << " " << opt_y << endl;
    }
}

Measured memory_bytes: 3040
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for (int i = 0; i < n; i++) {
			char[] carray = in.next().toCharArray();
			Arrays.sort(carray);
			int max = 0;
			int min = 0;
			for (int j = 0; j < 8; j++) {
				int val = Character.getNumericValue(carray[j]);
				min += (int) Math.pow(10, (7 - j)) * val;
				max += (int) Math.pow(10, j) * val;
			}
			System.out.println(max - min);
		}
	}
}

Measured memory_bytes: 12000
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

h = I()
mul = 1
ans = 0
while h > 0:
    h = floor(h/2)
    ans += mul
    mul *= 2

print(ans)

Measured memory_bytes: 63852
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#include<limits>
#include<bitset>
#include<ctype.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000000;
int main() {   
    int n;
    cin>>n;
    ll a[5]={};
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(s[0]=='M'){
            a[0]++;
        }else if(s[0]=='A'){
            a[1]++;
        }else if(s[0]=='R'){
            a[2]++;
        }else if(s[0]=='C'){
            a[3]++;
        }else if(s[0]=='H'){
            a[4]++;
        }
    }
    ll ans=1;
    bool f=false;
    ll s=0;
    for(int i=0;i<5;i++){
        if(a[i]!=0){
            ans*=a[i];
            s++;
        }
    }
    if(s<3){
        f=true;
    }
    if(f){
        ans=0;
    }else if(s==4||s==5){
        ans=0;
        for(int i=0;i<3;i++){
            for(int j=i;j<4;j++){
                for(int k=j;k<5;k++){
                    if(a[i]==0||a[j]==0||a[k]==0){
                        continue;
                    }
                    if(i==j||j==k||i==k){
                        continue;
                    }
                    ans+=a[i]*a[j]*a[k];
                }
            }
        }
    }
    cout<<ans<<endl;
}

                           


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var K int
	lunlun := make([]int, 0)
	fmt.Scan(&K)
	for i := 1; i <= 9; i++ {
		dfs(1, i, &lunlun)
	}
	sort.Ints(lunlun)
	fmt.Println(lunlun[K-1])
}

func dfs(d, val int, lunlun *[]int) {
	*lunlun = append(*lunlun, val)
	if d == 10 {
		return
	}
	for i := -1; i <= 1; i++ {
		add := val%10 + i
		if 0 <= add && add <= 9 {
			dfs(d+1, val*10+add, lunlun)
		}
	}
}


Measured memory_bytes: 8212
from collections import defaultdict as de
from collections import Counter as C
h,w,n=map(int,input().split())
s=[0]*10
c=de(int)
for i in range(n):
    a,b=map(int,input().split())
    for j in range(max(2,a-1),min(a+2,h)):
        for q in range(max(2,b-1),min(b+2,w)):
            c[(j,q)]+=1
a=C(c.values())
print((h-2)*(w-2)-sum(a.values()))
for i in range(1,10):
    print(a[i])

Measured memory_bytes: 152104
i = 0
while True:
    a,b = map(int, input().split())
    if (a == 0) and (b == 0):
        break
    elif a < b:
        print(str(a)+' '+str(b))
        i = i + 1
    else:
        print(str(b)+' '+str(a))
        i = i + 1


Measured memory_bytes: 5608
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
input=sys.stdin.readline  #危険！基本オフにしろ！

def BELLMANFORD(point,d,n):
    cost       = {node:-float("inf")for node in range(1,n+1)}
    preference = {node:None         for node in range(1,n+1)}      #最適路のこと 
    cost[point]= 0
    for i in range(n-1):                                  #経路の長さは最大n-1であるため
        for now,lis in d.copy().items():
            for nex,c in lis:
                if cost[nex]<cost[now]+c:
                    cost[nex]=cost[now]+c
                    preference[nex]=now
 
    negative=[0]*n                                        #負閉路の長さは最大nであるため
    
    for i in range(n):                  #閉路判定
        for now,lis in d.copy().items():
            for nex,c in lis:
                if negative[now-1]==1:
                    negative[nex-1]=1
                if cost[nex]<cost[now]+c:
                    cost[nex]=cost[now]+c
                    preference[nex]=now
                    negative[now-1]=1
 
    return cost,negative


def main():
    n,m=map(int,input().split())
    d=defaultdict(list)
    for i in range(m):
        a,b,c=map(int,input().split())
        d[a].append([b,c])
    x,y=(BELLMANFORD(1,d,n))
    if y[n-1]>0:
        print("inf")
    else:
        print(x[n])


if __name__ == '__main__':
    main()

Measured memory_bytes: 5752
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

void _main() {
  int D, N;
  cin >> D >> N;
  int ans = pow(100, D) * N;
  if (N == 100) ans += pow(100, D);
  cout << ans << "\n";
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a+1 == c && d == 1)cout << 1 << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 256
#include <cstdio>

const int maxn = 1e5 + 10;

int A[maxn];
int B[maxn];

int main()
{
	int N;
	scanf("%d", &N);
	long long sum = 0;
	for (int i = 0; i < N; ++i)
		scanf("%d", &A[i]), sum += A[i];
	long long t = 1ll * N * (N + 1) / 2;
	if (sum % t)
	{
		puts("NO");
		return 0;
	}
	long long cnt = sum / t;
	for (int i = 0; i < N; ++i)
		B[i] = A[(i + 1) % N] - A[i] - cnt;
	bool flag = true;
	for (int i = 0; i < N; ++i)
		if (B[i] > 0 || (-B[i]) % N)
			flag = false;
	puts(flag ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 896
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(x) for x in arr_data[1]]

print(max(arr)-min(arr))

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{
    int n;
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int g1=__gcd(i,j);
            for(int k=1;k<=n;k++){
                sum+=__gcd(g1,k);
            }
        }
    }
    cout<<sum<<"\n";
	return 0; 
} 


Measured memory_bytes: 3624
function f()
  n,x=map(x->parse(Int,x),split(readline()))
  as=map(x->parse(Int,x),split(readline()))
  l=0
  r=2*10^9
  while r-l>1
    m=div(l+r,2)
    c=0
    for a=as
      c+=div(a-1,m)
    end
    if c<=x
      r=m
    else
      l=m
    end
  end
  println(r)
end
f()

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

double D[3001][3001];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N;
	double p, ans=0;
	cin>>N>>p;
	D[0][1]=p;
	D[0][0]=1-p;
	for(int i=1;i<N;i++) {
		cin>>p;
		for(int j=0;j<=i;j++) {
			D[i][j]+=D[i-1][j]*(1-p);
			D[i][j+1]+=D[i-1][j]*p;
		}
	}
	for(int i=(N+1)/2;i<=N;i++) ans+=D[N-1][i];
	cout.precision(12);
	cout<<fixed<<ans<<'\n';
	return 0;
}

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

void solve(){
    lli i, j, h, w;
    cin >> h >> w;

    vector<vector<char>> grid(h, vector<char>(w));
    for(i = 0; i < h; i++){
        for(j = 0; j < w; j++){
            cin >> grid[i][j];
        }
    }

    lli dp[h][w];
    memset(dp, 0, sizeof(dp));
    dp[h - 1][w - 1] = 1;

    for(i = h - 1; i >= 0; i--){
        for(j = w - 1; j >= 0; j--){
            if(grid[i][j] != '#'){
                if(i + 1 < h) 
                    dp[i][j] += dp[i + 1][j], dp[i][j] %= MOD;
                if(j + 1 < w) 
                    dp[i][j] += dp[i][j + 1], dp[i][j] %= MOD; 
            }
        }
    }

    cout << dp[0][0];


}


int main(){
    solve();
}

Measured memory_bytes: 12424
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define pf push_front
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1000000007;
int ll_max=1e6;



int main() {
	// your code goes here
	IOS;
	ll n,m,i,j,d;
	
	
      ll x,y,t,b,c,k;
      cin>>x>>n;
      ll a[n];
      ll flag=0;
      rep(i,n){
            cin>>a[i];
            if(a[i]==x){
                  flag=1;
            }
      }
      if(flag==0){
            cout<<x;
      }
      else{
            sort(a,a+n);
            ll pos=0;
            while(a[pos]!=x&&pos<n){
                  pos++;
            }
            i=pos-1;
            j=pos+1;
            b=x-1;
            c=x+1;
            ll flag2;
            while(1){
                 if(b!=a[i]||i<0){
                       flag2=b;
                       break;
                 }
                 if(c!=a[j]||j>=n){
                       flag2=c;
                       break;
                 }
                 i--; j++;
                 b--; c++;
                  
            }
            cout<<flag2;
      }
      return 0;
}

Measured memory_bytes: 3628
x = int(input())

p = [None for _ in range(100)]

p[1] = (1,2,3,4,5,6,7,8,9)

def getByKeta(n):
    for i in p[n-1]:
        for j in range(-1, 2):
          d = i % 10 + j
          if d < 0 or d > 9:
              continue

          yield i * 10 + d

for i in range(2, 11):
    p[i] = tuple(getByKeta(i))

ans = 0
for i in range(1, 11):
    if x <= len(p[i]):
        ans = p[i][x-1]
        break
    x -= len(p[i])
print(ans)

# p = []
# for i in range(1, 10):
#   p.append(i)

# ans = 0
# index = x

# while 1:
#     if index <= len(p):
#       break
#     index -= len(p)
#     for i in p:
#       for j in range(-1, 2):
#           d = i % 10 + j
#           if d < 0 or d > 9:
#               continue

#           nx = i * 10 + d
#           p.append(nx)

# print(p)
# print(len(p))
# ans = p[1]
# print(ans)



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

int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    cout << a[0] << " " << a[1] << " " << a[2] << endl;
    return 0;

}

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    if(a>b*c) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}











Measured memory_bytes: 3640
fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length
    val dp = Array(n + 1) { Array(13) { 0L } }//dp[i][j] i文字目まで見た時の、13で割った余りがjであるものの数
    dp[0][0] = 1L
    for (i in 0 until n) {
        val c = if (s[i] == '?') -1 else s[i].toString().toInt()
        for (j in 0..9) {
            if (c != -1 && c != j) continue//s[i]が?の場合は全ての数字について試し、そうでない場合はその数字のみ試す
            for (ki in 0..12) dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]
        }
        for (ki in 0..12) dp[i + 1][ki] %= 1000000007L
    }
    println(dp[n][5])
}


Measured memory_bytes: 149780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const int inf = 1<<29;

int from_fen[100005], from_snu[100005];
vector<int> adj[100005];

void bfs(int d[], int start){
    queue<int> q;
    d[start] = 0;
    q.push(start);

    while(!q.empty()){
        int now = q.front(); q.pop();
        for(int to:adj[now]){
            if(d[to] != inf) continue;
            d[to] = d[now]+1;
            q.push(to);
        }
    }
}

int main(){
    int N; cin >> N;
    for(int i=0; i<N; ++i) { from_fen[i] = inf; from_snu[i] = inf; }
    for(int i=0; i<N-1; ++i){
        int a, b; cin >> a >> b;
        --a; --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    bfs(from_fen, 0);
    bfs(from_snu, N-1);

    int fen = 0, snu = 0;
    for(int i=0; i<N; i++){
        if(from_fen[i] <= from_snu[i]) ++fen;
        else ++snu;
    }

    if(fen > snu) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

Measured memory_bytes: 6656
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int D = scan.nextInt();
        int L = scan.nextInt();
        int x;
        int y;
        x = D/L;
        y = D%L;
        System.out.println(x+y);

    }

}



Measured memory_bytes: 26228
#include<bits/stdc++.h>
using namespace std;
int n,a[205],ans;
int main(){
	scanf("%d",&n);
	n*=2;
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i+=2)ans+=a[i];
	printf("%d",ans); 
} 

Measured memory_bytes: 256
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    dp = [INF] * (N + 2)
    dp[0] = 0

    for a in [9, 6]:
        for x in range(1, N):
            if a ** x > N:
                break
            for i in range(N):
                if i + a ** x <= N:
                    dp[i + a ** x] = min(dp[i + a ** x], dp[i] + 1)

    for i in range(N):
        if i + 1 <= N:
            dp[i + 1] = min(dp[i + 1], dp[i] + 1)

    print(dp[N])
if __name__ == '__main__':
    main()


Measured memory_bytes: 4908
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int V=233333;
const int E=520233;
struct G{
	int fir[V],nxt[E],to[E],cnt[V],tote,p[V];
	void adde(int u,int v){++cnt[u];to[++tote]=v;nxt[tote]=fir[u];fir[u]=tote;}
	int dfs(int u)
	{
		int o1=0,o2=0;
		for(int i=fir[u];i;i=nxt[i])
		{
			o2=dfs(to[i]);
			if(o1){p[o1]=o2;p[o2]=o1;o1=o2=0;}
			else o1=o2;
		}
		if(cnt[u]&1)return o1;
		else return u;
	}
}A,B;
int n,rtA,rtB,x[V];
void dfs(int u)
{
	if(!x[A.p[u]])
	{
		x[A.p[u]]=-x[u];
		dfs(A.p[u]);
	}
	if(!x[B.p[u]])
	{
		x[B.p[u]]=-x[u];
		dfs(B.p[u]);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1,f;i<=n;++i)
	{
		scanf("%d",&f);
		if(~f)A.adde(f,i);
		else rtA=i;
	}
	for(int i=1,f;i<=n;++i)
	{
		scanf("%d",&f);
		if(~f)B.adde(f,i);
		else rtB=i;
	}
	for(int i=1;i<=n;++i)if((A.cnt[i]^B.cnt[i])&1)return puts("IMPOSSIBLE"),0;
	puts("POSSIBLE");
	A.dfs(rtA);B.dfs(rtB);
	for(int i=1;i<=n;++i)
	{
		if(A.cnt[i]&1)printf("0 ");
		else
		{
			if(!x[i]){x[i]=1;dfs(i);}
			printf("%d ",x[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 14848
#include <iostream>
using namespace std;
#define REP(i,n) for (int i=0; i<n; i++)

int main(void){
	int c=0, W;
	char s;
	while (true){
		cin>>W;
		if (W==0) break;
		int dt[1001];
		REP(i,1001) dt[i]=0;
		c ++;

		int p,w,N;
		cin>>N;
		REP(i,N){
			cin>>p>>s>>w;
			for (int w0=W; w0>=0; w0--){
				int p0=dt[w0];
				if (w0==0 || p0!=0){
					int w1 = w0+w;
					int p1 = p0+p;
					if (w1<=W && dt[w1]<p1)	dt[w1]=p1;
				}
			}
		}
		int m=0,n;
		REP(i, W+1)
			if (dt[i]>m){
				m = dt[i];
				n = i;
			}
		cout<<"Case "<<c<<":"<<endl;
		cout<<m<<endl;
		cout<<n<<endl;
	}
}

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

int main()
{
	int h, w;
	while (cin >> h >> w, h || w)
	{
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++) cout << ((i + j) % 2 == 0 ? '#' : '.');
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 2996
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int d = sc.nextInt();
		long x = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= 10; i++) {
			x = r * x - d;
			sb.append(x).append("\n");
		}
		System.out.print(sb);
	}
}


Measured memory_bytes: 21844
from sys import stdin
from heapq import heappush, heappop


def main():
    Q = []

    for line in stdin.readlines():
        cmd = line.split()
        if cmd[0] == "insert":
            heappush(Q, -int(cmd[1]))
        elif cmd[0] == "extract":
            print(-heappop(Q))
        else:
            break


if __name__ == "__main__":
    main()


Measured memory_bytes: 188224
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int LLINF = 1LL << 60;
signed main()
{
    int N;
    int dist[305][305];
    bool flag = false;
    int sum = 0;
    cin >> N;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            cin >> dist[i][j];
        }
    }

    for(int k = 0; k < N; k++) {
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                if(dist[i][j] > dist[i][k] + dist[k][j]) {
                    flag = true;
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }

    if(flag) cout << -1 << endl;
    else {
        for(int k = 0; k < N; k++) {
            for(int i = 0; i < N; i++) {
                for(int j = 0; j < N; j++) {
                    if(i != k && j != k && i != j) {
                        if(dist[i][j] == dist[i][k] + dist[k][j]) {
                            dist[i][j] = LLINF;
                            dist[j][i] = LLINF;
                        }
                    }
                }
            }
        }
        for(int i = 0; i < N; i++) {
            for(int j = i + 1; j < N; j++) {
                if(dist[i][j] != LLINF) {
                    sum += dist[i][j];
                }
            }
        }
        cout << sum << endl;
    }
    return (0);
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <assert.h>
#include <iomanip>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;
const ll MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> a(M);
    for(int i = 0; i < M; i++) cin >> a[i];

    vector<ll> dp(N+1, 0), ef(N+1, 0);
    for(auto e : a) {
        ef[e] = -1;
    }
    dp[0] = 1;
    for(int i = 0; i <= N; i++) {
        bool f = true;
        if (f) {
            if(i - 1 >= 0 && ef[i] != -1) dp[i] += dp[i-1], dp[i] %= MOD;
            if(i - 2 >= 0 && ef[i] != -1) dp[i] += dp[i-2], dp[i] %= MOD;
        }
    }

    cout << dp[N] % MOD << endl;

    return 0;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        vector<PII> A(n);
        FOR(i,0,n) {
            int x,y; cin >> x >> y;
            A[i] = PII(x,y);
        }
        map<PII,int> cnt;
        FOR(i,0,n) FOR(j,0,n) if (i != j) {
            const int a = A[i].first  - A[j].first;
            const int b = A[i].second - A[j].second;
            if (a || b)
                cnt[PII(a,b)]++;
        }
        int ans = n;
        FOR_ALL(x,cnt)
            ans = min(ans, n - x->second);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Convert;
using static System.Console;
using static System.Math;
class MainClass
{
	static void Main(string[] args)
	{
		Answer();
	}
	public static void Answer()
	{
		//input
      var in1 = Console.ReadLine().Split(' ');
      var H = in1[0].ToInt();
      var W = in1[1].ToInt();
      Points points = new Points();
      for(int i = 0; i < H; i++)
      {
        var inSi = Console.ReadLine();
        for (int j = 0; j < W; j++)
        {
          var isBom = inSi[j] == '#';
          var p = new Point();
          p.i = i;
          p.j = j;
          p.isBom = isBom;
          points.list.Add(p);
        }
      }
      points.list
        .Where(_ => _.isBom)
        .ToList()
        .ForEach(p =>
                 {
                   points.numAdd(p, -1, -1);
                   points.numAdd(p, -1, 0);
                   points.numAdd(p, -1, 1);
                   points.numAdd(p, 0, -1);
                   points.numAdd(p, 0, 1);
                   points.numAdd(p, 1, -1);
                   points.numAdd(p, 1, 0);
                   points.numAdd(p, 1, 1);
                 });
      int count = 0;
      points.list.ForEach(p =>
                          {
                            if (count % W == 0)
                              Console.WriteLine();
                            if (p.isBom)
                              Console.Write("#");
                            else
                            {
                              Console.Write(p.numBomAround);
                            }
                            count++;
                          });	
	}
}
public class Point
        {
            public int i { get; set; }
            public int j { get; set; }
            public bool isBom { get; set; }
            public int numBomAround { get; set; } = 0;
        }
        public class Points
        {
            public List<Point> list { get; set; } = new List<Point>();

            public void numAdd( Point p,int di, int dj)
            {
                var target = this.list.FirstOrDefault(_ => _.i == p.i + di && _.j == p.j + dj);
                if (target != null)
                    target.numBomAround++;
            }
        }
    public static class Extension
    {
        public static int ToInt(this string num)
        {
            return int.Parse(num);
        }
    }

Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

vector<vector<int>> g(100005);
int ans = 0;
vector<bool> visited(100005);



int main() {
	int n, m;
	cin >> n >> m;
	int h[n];
	rep (i, n) cin >> h[i];
	rep (i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].pb(b);
		g[b].pb(a);
		if (h[a] == h[b]) {
			visited[a] = true;
			visited[b] = true;
		}
		else if (h[a] < h[b]) {
			visited[a] = true;
		}
		else {
			visited[b] = true;
		}
	}

	for (int i = 0; i < n; ++i) {
		if (!visited[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8804
//Volume1-0102
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//initialization
		int    out,
		       runner,
		       score;
		String s;

        //input
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while(n-- > 0){
        	out    = 0;
        	runner = 0;
        	score  = 0;
        	while(out != 3){
            	s = sc.next();
            	if(s.equals("HIT")){
            		if   (runner == 3){score++; }
            		else              {runner++;}
           		}
            	if(s.equals("OUT")){out++;}
            	if(s.equals("HOMERUN")){
            		score += runner + 1;
            		runner = 0;
            	}
        	}
        	System.out.println(score);
        }
	}
}

Measured memory_bytes: 15364
import java.util.*;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int k = scan.nextInt();
		int ans = 0;
		
		for(int i=1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				
				int first = gcd(i,j);
				for(int l=1;l<=k;l++) {
					ans += gcd(first,l);
				}
			}
		}
		
		System.out.println(ans);
	}	
	
	static int gcd (int a, int b) {
		int temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
}


Measured memory_bytes: 35804
#include<bits/stdc++.h>
using namespace std;
int W,H,N,a,x,y,b1,b2,b3,b4,i;
int main()
{
	cin>>W>>H>>N;
	b2=W;b4=H; 
	for(i=1;i<=N;i++)
	{
		cin>>x>>y>>a;
		if(a==1&&x>b1)b1=x;
		if(a==2&&x<b2)b2=x;
		if(a==3&&y>b3)b3=y;
		if(a==4&&y<b4)b4=y;
	}
	if(b2<=b1||b4<=b3)cout<<0;
	else cout<<(b2-b1)*(b4-b3);
	return 0;
}

Measured memory_bytes: 256
var
       x,y,z,kq,dai:longint;
 begin
       read(x,y,z);
       kq:=0;
       dai:=z;
       while dai+y+z<=x do
             begin
                   dai:=dai+y+z;
                   inc(kq);
             end;
       write(kq);
   end.

Measured memory_bytes: 128
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int main()
{
  char c;
  char s[100];
  _int64 left,right,mid,ans,prev;
  left=999999999;right=9999999999;
  while (right-left>1)
  {
    mid=(left+right)/2;
    printf("? %lld\n",mid);
    fflush(stdout);
    scanf("%s",s);
    if (s[0]=='Y') right=mid;
    else left=mid;
  }
  ans=left;
  if (ans==999999999)
  {
    printf("? %lld\n",ans);
    fflush(stdout);
    scanf("%s",s);
    if (s[0]=='N')
    {
      ans++;
      printf("! %lld\n",ans);
      return 0;
    }
    c='N';
  }
  else c='Y';
  while (1)
  {
    prev=ans;
    ans/=10;
    if (ans>0)
    {
      printf("? %lld\n",ans);
      fflush(stdout);
      scanf("%s",s);
    }
    if ((ans==0)||(s[0]==c))
    {
      ans=ans+1;
      break;
    }
  }
  printf("! %lld\n",ans);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
priority_queue <ll> P;
priority_queue <ll,vector <ll>,greater <ll> > Q;
 
int main() {
    int n;
    ll A=0,B=0,ans=0,l,r;
    cin>>n;
    for(int i=1;i<=n;i++) {
	cin>>l>>r;
	B+=r-l;
	P.push(r-A),Q.push(r-B);
	while(P.top()+A>Q.top()+B) {
	    ll x=P.top()+A,y=Q.top()+B;
	    P.pop(),Q.pop(),ans+=x-y;
	    P.push(y-A),Q.push(x-B);
	}
	A-=r-l;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int H,W;
   string w;
   w = "";
   for (int i=0;i<i+1;i++) {
       cin >> H >> W;
       if ( H==0 && W==0 ) {
           break;
       } else {
           for (int hoge=0;hoge<H;hoge++) {
               if ( hoge==0 || hoge==H-1 ) {
                    for (int j=0;j<W;j++) {
                        w = w + "#";
                    }
                    cout << w << endl;
                    w = "";
                } else {
                    for (int k=0;k<W;k++) {
                        if ( k==0 || k==W-1 ) {
                            w = w + "#";
                        } else {
                            w = w + ".";
                        }
                    }
                    cout << w << endl;
                    w = "";
                }
           }
       }
       cout << endl;
   }
}



Measured memory_bytes: 3012