akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		int a, b;
		cin >> a >> b;
		int c = INT_MAX;
		c = min({ a - 1,b - 1,(int)N - a,(int)N - b });
		if (c % 3 == 0) {
			cout << 1 << endl;
		}
		else if (c % 3 == 1) {
			cout << 2 << endl;
		}
		else {
			cout << 3 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3152
#include<cstdio>
#include<cctype>
#include<cstring>
using namespace std;
int main(void)
{
	char a[100000];
	scanf("%[^\n]",a);
	int b = strlen(a);
	for(int i = 0;i < b;i++)
	{
		a[i] = toupper(a[i]);
	}
	printf("%s\n",a);
	return 0;
}

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

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

  int N;
  cin >> N;
  cout << "ABC" << N << endl;
}

Measured memory_bytes: 256
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces
gi = lambda : list(map(int,input().split()))
n, m = gi()
vis = set()
ans = n + m;
while n not in vis:
	vis.add(n)
	ans = min(ans, n);
	n %= m
	vis.add(n)
	ans = min(ans, n);
	n = abs(n - m)
ans = min(ans, n);
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main()
{
  int n, x;
  cin >> n >> x;
  vector<int>l(n,0);
  for(auto & in: l){
    cin >> in;
  }
  int c = 1;
  int d = 0;
  while(d <= x && c < n + 2){
    //cout << d << endl;
    d += l[c - 1];
    c++;
  }
  cout << c - 1;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define fr(i,n) for(int i=0;i<n;i++)
#define int long long int
signed main() 
{
    FAST
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,k;
    cin>>n>>k;
    std::vector<int> v(n);
    fr(i,n) cin>>v[i];
    std::vector<bool> dp(k+1);
    fr(i,k+1)
    {
        fr(j,n)
        {
            if(v[j]<=i && !dp[i-v[j]])
                dp[i]=true;
        }
    }
    if(dp[k])cout<<"First";
    else cout<<"Second";
    return 0;
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define rep(i, a, b) for(int i = a;i < b; ++i)

main() {
    int n, m;
    string s, t;
    cin >> n >> m >> s >> t;
    int l = n * m / __gcd(n, m);
    rep(i, 0, n) {
        int pos = l/n*i;
        char c = s[i];
        if (pos * m % l == 0) {
            int j = pos * m / l;
            if (t[j] != s[i]) {
                    //cerr << j << ' ' << i << '\n';
                puts("-1");
                exit(0);
            }
        }
    }
    cout << l << '\n';
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
int n;
std::string s;
int x = 0;
int ans = 0;
int main() {
  std::cin >> n >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') {
      x++;
    }
    else {
      x--;
    }
    ans = std::max(ans, x);
  }
  std::cout << ans << std::endl;
}

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

int main()
{
  int N, l=0;
  cin>>N ;
  int A[N] ;
  for(int i=0; i<N; i++)
  {  cin>>A[i] ;
  }
  for(int j=0; j<N; j++)
  {  if(A[j]%2==0)
     {  if(A[j]%3==0||A[j]%5==0)
          l++;
        else
          l--;
     }
     else 
       l++;
  }
  if(l==N)
    cout<<"APPROVED";
  else
    cout<<"DENIED";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

ll findSum(ll a[], int N, ll size) {
      ll sum = 0;

      for(ll i=size-2; i>=size-(N*2); i-=2) {      // size - 2 - 2*(N-1) = size - 2 - 2N + 2 = size - 2N
            sum += a[i];
      }
      return sum;
}

int main() {
      int N;
      cin >> N;
      ll size = 3*N;
      ll a[size];
      for(ll i=0; i<size; i++) {
            cin >> a[i];
      }
      sort(a, a+size);

      cout << findSum(a, N, size) << endl;
}

Measured memory_bytes: 5424
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	int area = 0;
	int aroundLength = 0;

	cin >> a;
	cin >> b;

	area = a * b;
	aroundLength = (a + b) * 2;

	cout << area << " " << aroundLength << endl;

	return 0;
}

Measured memory_bytes: 1164
import math
import numpy as np
N = int(input())
m_list = []
max_p = math.floor(-1+math.sqrt(1+N))
for p in range(1, max_p+1):
   if N % p == 0:
       m = N//p -1
       m_list.append(m)
print(int(np.sum(m_list)))

Measured memory_bytes: 12508
s = input()
t = input()

ans = float('inf')

for i in range(len(s)-len(t)+1):
    tmp_s = s[i:i+len(t)]
    tmp_ans = 0
    for j in range(len(t)):
        if tmp_s[j] != t[j]:
            tmp_ans += 1
    ans = min(ans, tmp_ans)

print (ans)


Measured memory_bytes: 9064
import math
A,B,H,M = map(int, input().split())
m = 60*H+M
degA = 0.5*m 
degB = (6*m)%360
xa = A*math.sin(math.radians(degA))
ya = A*math.cos(math.radians(degA))
xb = B*math.sin(math.radians(degB))
yb = B*math.cos(math.radians(degB))
ans = math.sqrt((xa-xb)**2+(ya-yb)**2)
print(ans)

Measured memory_bytes: 9516
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <math.h>
using namespace std;

typedef long long signed int ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(),(obj).end()

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
  int N,Y,tmp;
  cin>>N>>Y;
  for(int i=0;i<=N;++i){
    for(int j=0;j<=(N-i);++j){
      if((i*1000+j*5000+(N-i-j)*10000)==Y){
        cout<<(N-i-j)<<" "<<j<<" "<<i<<endl;
        return 0;
      }
    }  
  }
	cout<<"-1 -1 -1"<<endl;
}


Measured memory_bytes: 256
if __name__ == '__main__':
    n = int(input())
    ps = [int(x) for x in input().split()]

    dis = []

    for n, p in enumerate(ps):
        if n + 1 != p:
            dis.append(p)

    if len(dis) == 2 or len(dis) == 0:
        print("YES")
    else:
        print("NO")

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

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

Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, l[210];

int main(){
	cin >> n;
	REP(i, 2 * n)cin >> l[i];
	sort(l, l + 2 * n);
	int ans = 0;
	for (int i = 0; i < 2 * n; i += 2){
		ans += l[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {

	var N int
	fmt.Scanf("%d\n", &N)

	var result []string
	m := map[string]int{}
	for i := 0; i < N; i ++ {
		
		var S string
		fmt.Scanf("%s", &S)
		m[S] += 1
	}
	
	var max int
	for key, v := range m {
		if v < max {
			continue
		}
		if v == max {
			result = append(result, key)
		}
		if v > max {
			max = v
			result = []string{key}
		}
	} 
	sort.Strings(result)
	for _, s := range result {
		fmt.Println(s)
	}
}

Measured memory_bytes: 34944
#include<stdio.h>
#include<iostream>
#include<map>
using namespace std;
const int maxn = 2e6 + 10;
int fa[maxn], ma[maxn];
void init(int n)
{
    for(int i = 0; i <= n; ++ i)
    {
        fa[i] = i;
        ma[i] = i;
    }
}
int find(int* fa, int x)
{
    if(fa[x] == x)
    {
        return fa[x];
    }
    return fa[x] = find(fa, fa[x]);
}
void unin(int a, int b, int* fa)
{
   a = find(fa, a);
   b = find(fa, b);
   fa[a] = b;
}
map<pair<int, int>, int>ans;
int main()
{
    int n, k, l;
    while(scanf("%d%d%d", &n, &k, &l) != EOF)
    {
        init(n);
        ans.clear();
        for(int i = 0; i < k; ++ i)
        {
            int a, b;
            scanf("%d%d", &a, &b);
            unin(a, b, ma);
        }
        for(int i = 0; i < l; ++ i)
        {
            int a, b;
            scanf("%d%d", &a, &b);
            {
                unin(a, b, fa);
            }
        }
        for(int i = 1; i <= n; ++ i)
        {
            ans[make_pair(find(ma, i), find(fa, i))]++;
        }
        for(int i = 1; i <= n; ++ i)
        {
            i == n ? printf("%d\n", ans[make_pair(find(ma, i), find(fa, i))]) : printf("%d ", ans[make_pair(find(ma, i), find(fa, i))]);
        }
    }
    return 0;
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int long long
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

int lcm(int, int);
map<int,int> GetPrimeFactors(int);
bool IsPrime(int);
int Factorial(int);
int npr (int, int);
int ncr (int, int);

/***** MAIN *****/
void Main() {
  int a, b, c, n = 0;
  cin >> a >> b >> c;
  if(a == b) ++n;
  if(b == c) ++n;
  if(a == c) ++n;
  if(n == 1) cout << "Yes";
  else cout << "No";
  
  cout << "\n";
}
/***** MAIN *****/

signed main() {
  cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
  Main();
  return 0;
}

int lcm(int a, int b) { return a / __gcd(a,b) * b;}

map<int,int> GetPrimeFactors(int n) {
  map<int,int> mp;
  // dived by 2, 3, 5, ...
  for(int i=2; i*i<=n; i+=2) {
    if(i==4) i = 3;
    while(n%i == 0) {
      ++mp[i];
      n /= i;
    }
  }
  if(n!=1) ++mp[n];

  return mp;
}

bool IsPrime(int a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(int i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

int Factorial(int n){
  int ans = 1;
  while(n > 1){
    ans *= n;
    --n;
  }
  return ans;
}

int npr(int n, int r) {
  return Factorial(n)/Factorial(n-r);
}

int ncr (int n, int r){
  return npr(n,r)/Factorial(r);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rept(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}

void yes() {
	cout << "Yes" << endl;
}

void no() {
	cout << "No" << endl;
}

int main() {
	ll a, b, k;
	cin >> a >> b >> k;
	
	if (a >= k) {
		cout << (a - k) << " " << b << endl;
	}
	else if ((a + b) >= k) {
		cout << 0 << " " << b - (k - a) << endl;
	}
	else {
		cout << 0 << " " << 0 << endl;
	}

	system("pause");
	return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>
#include<map>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)


int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if (b > n* a) {
		cout << n * a << endl;
	}
	else {
		cout << b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################
N = int(input())
ans = "" 
for i in range(10000):
    N -= 1
    tmp = N%26
    ans += chr(97+tmp)
    N //= 26
    if N <= 0:
        break
 
print(ans[::-1])


Measured memory_bytes: 9356
lines = $stdin.read
array = lines.split("\n")
 
TIME = 10**5*2
 
N,C = array[0].split(" ").map(&:to_i)
 
cumsum = Array.new(C).map{Array.new(TIME,0)}
 
array[1..N+1].each do |rec|
  s,t,c  = rec.split(" ").map(&:to_i)
  s,t=s*2-1,t*2     # double
  s,t,c=s-1,t-1,c-1 # 0-indexed
  cumsum[c][s] += 1
  cumsum[c][t] -= 1
end
 
ans = Array.new(TIME,0)
cumsum.each do |sum|
  for i in 1...sum.length
    sum[i] += sum[i-1]
    ans[i] += 1 if sum[i] > 0
  end
end
puts ans.max


Measured memory_bytes: 59772
#include<iostream>
#include<cmath>
using namespace std;
long long f(long long a,long long b){
    int x=0,y=0;
    do{
        a/=10;
        x++;
    }while(a!=0);
    do{
        b/=10;
        y++;
    }while(b!=0);
    return max(x,y);
}

int main(){
    long long ans=11,n;
    cin>>n;
    for(long long i = 1; i*i <=n ; i++)if(n%i==0)ans=min(ans,f(i,n/i));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#ifdef __APPLE__
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif

const int N = (int)51;
const int MOD = (int)1e9 + 7;
const int inf = (int)5e8;
const long long infll = (long long)1e17;

int cnt[2];


long long c[N + 1][N + 1];

void solve() {
    int n, p;
    scanf("%d %d", &n, &p);
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        ++cnt[x & 1];
    }
    for (int n=0; n <= N; ++n) {
        c[n][0] = c[n][n] = 1;
        for (int k=1; k<n; ++k)
            c[n][k] = c[n-1][k-1] + c[n-1][k];
    }

    long long total = 0;
    if (p == 0) {
        for (int i = 0; i <= cnt[1]; i += 2) {
            total += c[cnt[1]][i];
        }
    } else {
        for (int i = 1; i <= cnt[1]; i += 2) {
            total += c[cnt[1]][i];
        }
    }
    printf("%lld\n", (1LL << cnt[0]) * total);
}

int main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int r;
    cin >> r;
    cout << r*r;
}

Measured memory_bytes: 256
#include <iostream>

#define MOD 1000000007
#define MAX 2000000 
using namespace std;

typedef long long int lli;

lli fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
lli COM(lli n, lli k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
  lli X,Y;
  COMinit();
  cin >> X >> Y;
  // condition
  if(2*X-Y < 0 || (2*X-Y)%3 != 0 || -X+2*Y < 0 || (-X+2*Y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }
  lli p,q;
  p = (lli)(2*X-Y)/3;
  q = (lli)(-X+2*Y)/3;
  if(p > q){
    swap(p,q);
  }
  //(p+q)
  cout << COM(p+q,p) << endl;
  return 0;
}



Measured memory_bytes: 47104
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility> // pair
using namespace std;

struct Point {
  int x, y;
};

int main() {
  const int M = 30;
  int w, h;
  while (scanf("%d%d", &w, &h) != EOF && w && h) {
    // 隣接リスト作成
    int d;
    vector<Point> V[M][M];
    for (int i=0; i<h; i++) {
      for (int j=0; j<w-1; j++) {
	scanf("%d", &d);
	if (d == 0) {
	  Point p = { i, j+1 };
	  V[i][j].push_back(p);
	  // cerr << "Connect (" << i << "," << j << ") and (" << i << "," << j+1 << ")" << endl;
	  p = { i, j };
	  V[i][j+1].push_back(p);
	}
      }
      if (i != h-1) {
	for (int j=0; j<w; j++) {
	  scanf("%d", &d);
	  if (d == 0) {
	    Point p = { i+1, j };
	    V[i][j].push_back(p);
	    // cerr << "Connect (" << i << "," << j << ") and (" << i+1 << "," << j << ")" << endl;
	    p = { i, j };
	    V[i+1][j].push_back(p);
	  }
	}
      }
    }
    // 幅優先探索
    queue<pair<Point,int>> Q;
    bool visited[M][M];
    fill(&visited[0][0], &visited[0][0]+M*M, false);
    Point p = {0, 0};
    Q.push(make_pair(p, 0));
    while (! Q.empty()) {
      p = Q.front().first;
      // cerr << "Visiting (" << p.x << "," << p.y << ")" << endl;
      int count = Q.front().second;
      Q.pop();
      if (! visited[p.x][p.y]) {
	visited[p.x][p.y] = true; // これがないと無限ループ！
	if (p.x == h-1 && p.y == w-1) {
	  printf("%d\n", count+1);
	  goto END;
	}
	for (unsigned int i=0; i<V[p.x][p.y].size(); i++) {
	  Point q = V[p.x][p.y][i];
	  if (! visited[q.x][q.y]) {
	    Q.push(make_pair(q, count+1));
	  }
	}
      }
    }
    printf("0\n");
  END: continue;
  }
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int h,w,k;cin>>h>>w>>k;
    string s[h];
    rep(i,0,h)cin>>s[i];
    int ans[h][w];
    memset(ans,0,sizeof ans);
    int now=1;
    vector<ll> v;
    rep(i,0,h){
        int c=-1;
        rep(j,0,w){
            if(s[i][j]=='#'){
                c=j;
            }
        }
        if(c==-1)continue;
        v.push_back(i);
        rep(j,0,c+1){
            ans[i][j]=now;
            if(s[i][j]=='#')now++;
        }
        rep(j,c+1,w)ans[i][j]=now-1;
    }
    int y=0;
    rep(i,0,h){
        if(ans[i][0]>0)continue;
        while(y<v.size()&&v[y]<i)y++;
        if(y==v.size())y--;
        rep(j,0,w){
            ans[i][j]=ans[v[y]][j];
        }
    }
    rep(i,0,h){
        rep(j,0,w)cout<<ans[i][j]<<" ";
        cout<<endl;
    }
}


Measured memory_bytes: 1280
def solve():
    n,m,x,y = map(int, input().split())
    X = max(map(int, input().split()))
    Y = min(map(int, input().split()))
    if X < y and x < Y and X < Y:
        return 'No War'
    else:
        return 'War'


if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 3060
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

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

    string S;
    cin >> S;

    vector<int> v(1, 1);
    for (int i = 1; i < N; i++) {
        if (S[i] == S[i - 1])
            v.back()++;
        else
            v.push_back(1);
    }

    int ans = 0;
    for (int i = 0; i < (int)v.size(); i++)
        ans += v[i] - 1;

    int cnt = (int)v.size();
    while (K != 0 && cnt > 2) {
        ans += 2;

        K--;
        cnt -= 2;
    }

    if (K != 0 && cnt == 2)
        ans++;

    cout << ans << endl;

    //for (int i = 0; i < (int)v.size(); i++)
    //    cout << v[i] << endl;

    return 0;
}


Measured memory_bytes: 1020
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sA = sum(A)
for i in range(N):
    m = A[i]
    A[i] = max(0,A[i]-B[i])
    B[i] = B[i]-m+A[i]
    A[i+1] = max(0,A[i+1]-B[i])
print(sA-sum(A))



Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
char mat[1001][1001];
long long dp[1001][1001];
long long m,n;
long long M=1e9+7;
long long func(long long i,long long j)
{
    //cout<<i<<" "<<j<<endl;
    if(i ==m && j==n)
    return 1;
    if(i>m || j>n || mat[i][j] == '#')
    {
        //dp[i][j]=0;
        return 0;
    }
    if(dp[i][j] != -1)
    return dp[i][j];
    dp[i][j] = (func(i+1,j)+func(i,j+1))%M;
    return dp[i][j];
}
int main()
{
    
    cin>>m>>n;
    for(long long i=0;i<m;++i)
    for(long long j=0;j<n;++j)
    cin>>mat[i+1][j+1];
    memset(dp,-1,sizeof(dp));
    long long ans=func(1,1);
    cout<<ans;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main(){
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // string s;
    // cin>>s;
   	// int flag=1;
    // for(int i=0;i<s.size();++i){
    // 	for(int j=i+1;j<s.size();++j){
    // 		if(s[i]==s[j]){
    // 			flag=0;
    // 			break;
    // 		}
    // 	}
    // }
    // cout<<((flag)?"yes":"no");



    // string s;
    // cin>>s;
    // set<char>c;
    // for(char k:s) c.insert(k);
    // cout<<((s.size()==c.size())?"yes":"no");
    


    // string s;
    // cin>>s;
    // map<char,int>m;
    // for(int i=0;i<s.size();++i){
    // 	if(m[s[i]]>0){
    // 		cout<<"no";
    // 		return 0;
    // 	}
    // 	++m[s[i]];
    // }
    // cout<<"yes";

    // int a,b;
    // cin>>a>>b;
    // int ans=a+b;
    // (ans>=10)?cout<<"error":cout<<ans;
    

    // int n;
    // cin>>n;
    // int a,mx=0,mi=1000;
    // for(int i=0;i<n;++i){
    // 	cin>>a;
    // 	if(mx<a) mx=a;
    // 	if(mi>a) mi=a;
    // }


    // int n;
    // cin>>n;
    // int ar[n];
    // for(int i=0;i<n;++i) cin>>ar[i];
   	// cout<<*max_element(ar,ar+n)-*min_element(ar,ar+n);
    

    // int n,m;
    // cin>>n>>m;
    // n+=2;
    // m+=2;
    // for(int i=0;i<n;++i){
    // 	for(int j=0;j<m;++j){
    // 		if(i==0 || i==n-1 || j==0 || j==m-1) cout<<"#";
    // 		else{
    // 			char c;
    // 			cin>>c;
    // 			cout<<c;
    // 		}
    // 	}
    // 	cout<<'\n';
    // }

    // int x,y;
    // cin>>x>>y;
    // int ar[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
    // cout<<((ar[x]==ar[y])?"Yes":"No");
    

    // string a,b,c;
    // cin>>a>>b>>c;
    // cout<<(((a.back()==b.front()) && (b.back()==c.front()))?"YES":"NO");
    
    int a,b,c;
    cin>>a>>b>>c;
    cout<<((a<=c && c<=b)?"Yes":"No");
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
 
int a[1005];
long long dp[1005];
vector<int> op[1005], oa;
 
int main()
{
    int n, ai=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",a+i);
    dp[1] = a[1];
    dp[2] = a[2];
    long long ans = max(dp[1],dp[2]);
    op[2].push_back(1);
    if(ans == dp[2]) ai = 2;
    for(int i=3;i<=n;i++)
    {
        dp[i] = max((long long)a[i],dp[i-2]+a[i]);
        if(dp[i-2] > dp[i])
        {
            dp[i] = dp[i-2];
            op[i] = op[i-2];
            op[i].push_back(3);
        }
        else if(dp[i] == a[i])
        {
            op[i] = op[i-2];
            op[i].push_back(1);
            op[i].push_back(1);
        }
        else
        {
            op[i] = op[i-2];
            op[i].push_back(2);
        }
        if(dp[i]>ans)
        {
            ans = dp[i];
            ai = i;
        }
    }
    int m = n - ai + 1;
    while(m>1) op[ai].push_back(m--);
    printf("%lld\n%d\n",ans,op[ai].size());
    for(int i : op[ai]) printf("%d\n",i);
}


Measured memory_bytes: 2432
INTEGER :: N, K, i, j, ans
INTEGER, ALLOCATABLE :: p(:)
READ*, N, K
ALLOCATE( p(N) )
READ*, p
DO i = 1, n
	DO j = 2, n
		IF(p(j) .lt. p(j-1)) THEN
			ans = p(j)
			p(j) = p(j-1)
			p(j-1) = ans
		END IF
	END DO
END DO
ans = 0
DO i = 1, K
	ans = ans + p(i)
END DO
PRINT*, ans
END

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

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    int n = s.length();  
    if(s.length()==2){
        if(s[0]==s[1]) cout<<"1 2";
        else cout<<"-1 -1";
        return 0;
    }
    bool f = false;
    for(int i=0; i+1<n; i++){
        if(s[i]==s[i+1]) {
            cout<<i+1<<" "<<i+2;
            f = true;
            break;
        }
    }
    for(int i=0; i+2<n && f!=true; i++){
        if(s[i]==s[i+1] || s[i+2]==s[i+1] || s[i]==s[i+2]) {
            cout<<i+1<<" "<<i+3;
            f = true;
            break;
        }
    }
    if(!f) cout<<"-1 -1";
    return 0;
}

Measured memory_bytes: 3756
# -*- coding: utf-8 -*-
import sys


K,N = map(int,input().split())
A = list(map(int,input().split()))

B = [0]*(N)
for i in range(N-1):
    B[i] = A[i+1]-A[i]

B[N-1] = A[0] + K - A[-1]

B.sort()
ans = sum(B[:-1])
print(ans)


Measured memory_bytes: 26444
N = int(input())
lst = [int(input()) for _ in range(N)]
lst = [0] + lst
lst2 = [0] * (N + 1)
i = 1
ret = 1
while True:
    if lst[i] == 2:
        break
    if lst2[i] == 1:
        ret = -1
        break
    ret += 1
    lst2[i] = 1 
    i = lst[i]
    
print(ret)

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

string data[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
int day[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

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

	int m, d;
	while(cin >> m >> d && m != 0){

		for(int i = 0; i < m - 1; ++i){
			d += day[i];
		}

		d -= 1;
		cout << data[(d + 3) % 7] << endl;
	}

	return 0;
}

Measured memory_bytes: 1196
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;

int L[100005];
int main() {
	int n, a;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a);
		L[a] = i;
	}
	for (int i = 1; i <= n; i++) {
		if (i == n) {
			printf("%d\n", L[i]);
		}
		else printf("%d ", L[i]);
	}

	return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    const string s = "FESTIVAL";
    ll k;
    cin >> k;

    string t = "";
    REP(i, 600) t += "FESTIVA";
    vector<ll> cnt(8), f(600);
    cnt[0] = 1;
    REP(i, t.size()) {
        cnt[i%7+1] += cnt[i%7];
        if(i%7==6) f[i/7] = cnt[7];
    }

    string ans = "";
    for(ll i=599; i>=0; --i) {
        ll num = k / f[i];
        ans += string(num, 'L');
        ans += "AVITSEF";
        k %= f[i];
    }
    reverse(ALL(ans));
    cout << ans << endl;

    // {
    //     vector<ll> cnt(9);
    //     map<char,ll> trans;
    //     REP(i, 8) trans[s[i]] = i+1;
    //     cnt[0] = 1;
    //     REP(i, ans.size()) {
    //         ll idx = trans[ans[i]];
    //         cnt[idx] += cnt[idx-1];
    //     }
    //     cout << cnt[8] << endl;
    // }

    return 0;
}


Measured memory_bytes: 256
S=input()

start=0
for i in range(len(S)):
    start=i
    if S[i]=='B':
        break

left_W=start
ans=0
if start<len(S)-1:
    for i in range(start+1,len(S)):
        if S[i]=='W':
            ans+=i-left_W
            left_W+=1

print(ans)

Measured memory_bytes: 9264
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
ll n;
ll read()
{
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return f*x;
}
ll calc(ll x)
{
	if(x==1) return 1;
	return 2*calc(x/2)+1;
}
int main()
{
	n=read();
	printf("%lld",calc(n));
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int m,f,r;
    int a[50][3];
    
    int i=0,j=0;
    
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        
        if(m==-1 && f==-1 && r==-1){
            break;
        }
        
        a[i][0]=m;
        a[i][1]=f;
        a[i][2]=r;
        
        i++;
    }

//    for(j=0;j<i;j++){
//        printf("%d ",a[j][0]);
//        printf("%d ",a[j][1]);
//        printf("%d\n",a[j][2]);
//    }

    for(j=0;j<i;j++){
        if(a[j][0]==-1 || a[j][1]==-1){
            printf("F");
        }else if(80<=a[j][0]+a[j][1]){
            printf("A");
        }else if(65<=a[j][0]+a[j][1] && a[j][0]+a[j][1]<80){
            printf("B");
        }else if(50<=a[j][0]+a[j][1] && a[j][0]+a[j][1]<65){
            printf("C");
        }else if(30<=a[j][0]+a[j][1] && a[j][0]+a[j][1]<50){
            if(50<=a[j][2]){
                printf("C");
            }else{
                printf("D");
            }
        }else if(a[j][0]+a[j][1]<30){
            printf("F");
        }
        printf("\n");
    }
    
    
    
    
    return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e18;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};


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

  if (k % 2 == 0) cout << a-b << endl;
  else cout << b-a << endl;

  return 0;
}


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

unsigned int calc(unsigned int step,const pair<int,int>& cur,vector< vector<unsigned int> >& sht,const int& w,const int& h,vector< vector<int> >& vwall,vector< vector<int> >& hwall){
	unsigned int sub,ret=-1;
	if(cur.first==w-1&&cur.second==h-1)return step;
	if(sht[cur.second][cur.first]<=step)return -1;
	sht[cur.second][cur.first]=step;
	if(cur.first!=0){
		if(vwall[cur.second][cur.first-1]!=1){
			sub=calc(step+1,pair<int,int>(cur.first-1,cur.second),sht,w,h,vwall,hwall);
			if(sub<ret)ret=sub;
		}
	}
	if(cur.first!=w-1){
		if(vwall[cur.second][cur.first]!=1){
			sub=calc(step+1,pair<int,int>(cur.first+1,cur.second),sht,w,h,vwall,hwall);
			if(sub<ret)ret=sub;
		}
	}
	if(cur.second!=0){
		if(hwall[cur.second-1][cur.first]!=1){
			sub=calc(step+1,pair<int,int>(cur.first,cur.second-1),sht,w,h,vwall,hwall);
			if(sub<ret)ret=sub;
		}
	}
	if(cur.second!=h-1){
		if(hwall[cur.second][cur.first]!=1){
			sub=calc(step+1,pair<int,int>(cur.first,cur.second+1),sht,w,h,vwall,hwall);
			if(sub<ret)ret=sub;
		}
	}
	return ret;
}
int main(){
	while(true){
		int w,h;
		unsigned int ret;
		vector< vector<int> > vwall,hwall;
		vector< vector<unsigned int> > sht;
		cin>>w>>h;
		if(w==0)break;
		vwall.resize(h);
		hwall.resize(h-1);
		sht.resize(h);
		for(int y=0;y<h-1;y++){
			vwall[y].resize(w-1);
			hwall[y].resize(w);
			sht[y].resize(w);
			for(int x=0;x<w-1;x++){
				cin>>vwall[y][x];
			}
			for(int x=0;x<w;x++){
				cin>>hwall[y][x];
				sht[y][x]=-1;
			}
		}
		vwall[h-1].resize(w-1);
		sht[h-1].resize(w);
		for(int x=0;x<w-1;x++){
			cin>>vwall[h-1][x];
			sht[h-1][x]=-1;
		}
		ret=calc(1,pair<int,int>(0,0),sht,w,h,vwall,hwall);
		cout<<((ret==-1)?0:ret)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1296
length = int(input())
target = []
for i in range(length):
    s, e = map(int, input().split(" "))
    target.append([s - e, s + e])
target.sort(key = lambda x: x[1])
answer = 0
before_e = -float("inf")
for s, e in target:
    # print(before_e, s, e)
    if s < before_e:
        answer += 1
    else:
        before_e = e
print(length - answer)

Measured memory_bytes: 21336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	int h, w, sy, sx, gy, gx;
	cin >> h >> w >> sy >> sx >> gy >> gx;
	sy--, sx--, gy--, gx--;
	V<string> s(h);
	rep(i, h)cin >> s[i];

	vvi d(h, vi(w, INF));
	V<V<bool>> visit(h, V<bool>(w, false));
	deque<P> dq;
	dq.push_back(P(sy, sx));
	d[sy][sx] = 0;

	while (!dq.empty()) {
		P p = dq.front();
		int y = p.first;
		int x = p.second;
		dq.pop_front();

		if (visit[y][x])continue;

		vi dy = { 0,0,1,-1 };
		vi dx = { 1,-1,0,0 };
		rep(i, 4) {
			int ey = y + dy[i];
			int ex = x + dx[i];
			if (ey < 0 || h <= ey)continue;
			if (ex < 0 || w <= ex)continue;
			if (d[ey][ex] <= d[y][x])continue;
			if (s[ey][ex] == '#')continue;
			d[ey][ex] = d[y][x];
			dq.push_front(P(ey, ex));
		}

		rep_lr(i, -2, 3)rep_lr(j, -2, 3) {
			int ey = y + i;
			int ex = x + j;
			if (ey < 0 || h <= ey)continue;
			if (ex < 0 || w <= ex)continue;
			if (d[ey][ex] <= d[y][x])continue;
			if (s[ey][ex] == '#')continue;
			d[ey][ex] = d[y][x] + 1;
			dq.push_back(P(ey, ex));
		}

		visit[y][x] = true;

	}

	if (d[gy][gx] == INF)d[gy][gx] = -1;
	cout << d[gy][gx] << endl;

}

Measured memory_bytes: 10064
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

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

	if (2*(k - 1) < n) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}


 

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

#define lli long long int
#define ii pair<int, int>
#define iii pair<int, ii>
#define ll pair<lli, lli>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second

using namespace std;

int main() {
	int n, m, dist[25][25][25][25], inf = 1000000000, x, y, nx, ny, ans = 0;
	int dx[] = {-1, 0, 0, 1};
	int dy[] = {0, -1, 1, 0};
	char s[25][25];
	queue<iii> q;
	iii u;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%s", s[i]);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			for (int k = 0; k < n; k++)
				for (int l = 0; l < m; l++)
					dist[i][j][k][l] = inf;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (s[i][j] == '.') {
				dist[i][j][i][j] = 0;
				q.push(mp(0, mp(i, j)));
				while (!q.empty()) {
					u = q.front();
					q.pop();
					x = u.se.fi;
					y = u.se.se;
					for (int k = 0; k < 4; k++) {
						nx = x + dx[k];
						ny = y + dy[k];
						if ((0 <= nx) && (nx < n) && (0 <= ny) && (ny < m))
							if (s[nx][ny] == '.')
								if (dist[i][j][nx][ny] > u.fi + 1) {
									dist[i][j][nx][ny] = u.fi + 1;
									q.push(mp(u.fi + 1, mp(nx, ny)));
									ans = max(ans, u.fi + 1);
								}
					}
				}
			}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1280
use std::io::*;

fn main() {
    let stdin = stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let buf = buf.trim();
    let chars:Vec<&str> = buf.split(' ').collect();
    let mut arr:Vec<i64> = Vec::new();
    for i in chars {
        match i {
            "+"| "-"| "*" => {
                let right = arr.pop().unwrap();
                let left = arr.pop().unwrap();
                let r = match i {
                    "+" => left + right,
                    "-" => left - right,
                    "*" => left * right,
                    _ => panic!()
                };
                arr.push(r);
            },
            _ => arr.push(i.parse::<i64>().unwrap())


        }
    }
    println!("{}", arr[0]);
}



Measured memory_bytes: 5040
n,k,c = map(int,input().split())
S = list(input())
L = [0]*k
nx = -1
cnt = 0
for i,s in enumerate(S):
    if i <=nx: continue
    if s =='o':
        L[cnt] = i
        nx = i + c
        cnt += 1
        if cnt ==k: break
R = [0]*k
nx = -1
cnt = 0
for i,s in enumerate(S[::-1]):
    if i <=nx: continue
    if s =='o':
        R[cnt] = n-i-1
        nx = i + c
        cnt += 1
        if cnt ==k: break
for l,r in zip(L,R[::-1]):
    if l ==r:print(l+1)

Measured memory_bytes: 88892
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val c = sc.nextInt()
    val b = (0 until m).map { sc.next().toInt() }
    val a = (0 until n).map { (0 until m).map { sc.next().toInt() } }
    println(problem121b(n, m, c, b, a))
}

fun problem121b(
    n: Int,
    m: Int,
    c: Int,
    b: List<Int>,
    a: List<List<Int>>
): Int {
    var ans = 0
    for (i in 0 until n) {
        val ai = a[i]
        var sum = 0
        for (j in 0 until m) {
            sum += ai[j] * b[j]
        }
        sum += c
        if (sum > 0) ans++
    }
    return ans
}

Measured memory_bytes: 31396
# Author: cr4zjh0bp
# Created: Sat Mar 28 11:53:27 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict

n, x, y = na()
x -= 1
y -= 1

dic = defaultdict(int)
for i in range(n):
    for j in range(i + 1, n):
        dist = min(j - i, 1 + abs(x - i) + abs(y - j))
        dic[dist] += 1

for i in range(1, n):
    print(dic[i])

Measured memory_bytes: 49116
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#define il inline
#define re register
#define fo(i,j,k) for(register int i=j;i<=k;i++)
#define do(i,j,k) for(register int i=j;i>=k;i--) 
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
il ll read()
{
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f*x;	
}
/*int h[200010],v[200010],dis[200010];
struct edge
{
	int v,w,next;
}e[200010*2];
il void add(int u,int v,int w)
{
	e[++cnt].v=v;
	e[cnt].w=w;
	e[cnt].next=h[u];
	h[u]=cnt;
}*/
ll n,k,ans;
ll dp[100010];
const ll mod=1e9+7;
ll cal(ll a,ll b)
{
    ll ret=1;
    while(b)
    {
        if(b&1) ret=(ret*a)%mod;
        a=(a*a)%mod;
        b>>=1LL;
    }
    return ret;
}
int main()
{
	//easy
    n=3,k=read();
    for(re ll i=k;i>=1;i--)
    {
        ll num=k/i;
        dp[i]=cal(num,n);
        for(ll j=2*i;j<=k;j+=i)
        {
            dp[i]=(dp[i]-dp[j]+mod)%mod;
        }
        ans=(ans+dp[i]*i)%mod;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include <utility>
#include<unordered_set>
#include <algorithm>
using namespace std;



int main(){
	int N, H;
	cin>>N>>H;
	
	vector<int> a(N,0);
	vector<int> b(N,0);
	for(int i =0; i < N; i++)
		cin>>a[i]>>b[i];
	
	if(H <= 0){
		cout<< 0 <<"\n";
		return 0;
	}
		
	
	int max_a = 0;
	for(int i =0; i < N; i++){
		max_a = max(max_a,a[i]);
	}
	
	sort(b.begin(),b.end());
	int count = 0;
	for(int i = N-1; i >=0; i--){
		if(b[i] > max_a){
			count++;
			H -= b[i];
			if(H <=0){
				cout<< count <<"\n";
				return 0;
			}
		}
	}
	
	int ans = count + H/max_a;
	if(H%max_a !=0)
		ans++;
	
	cout<< ans <<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>

int main(){
   int n;
   scanf("%d",&n);

   //配列の初期化
   bool card[4][13];
   for(int i = 0; i < 4; i++){
       for(int j = 0; j < 13; j++){
           card[i][j] = false;
       }
   }
   

   for(int i =0; i < n; i++){
       //カードの絵柄
       char c;
       scanf("\n%c", &c);

       //カードの数字
       int x;
       scanf("%d", &x);

       //配列にtrueを代入して行く
       //スペードの場合
       if(c == 'S'){
           card[0][x - 1] = true;
       }
       //ハートの場合
       else if(c == 'H'){
           card[1][x - 1] = true;
       }
       //クラブの場合
       else if(c == 'C'){
           card[2][x - 1] = true;
       }
       //ダイヤの場合
       else if(c == 'D'){
           card[3][x - 1] = true;
       }



   }
   //出力
   for(int i = 0; i < 4; i++){
       for(int j = 0; j < 13; j++){
           if(!card[i][j]){
               if(i == 0) {
                   printf("S %d\n", j + 1);
               }
               else if(i == 1){
                   printf("H %d\n", j + 1);
               }
               else if(i == 2){
                   printf("C %d\n", j + 1);
               }
               else if(i == 3){
                   printf("D %d\n", j + 1);
               }
           }
       }
       


   }

   return 0;
}


Measured memory_bytes: 2668
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
using namespace std;
int main(){
  int i,j,n;
  cin>>n;
  for(i=0;i<15;i++){
    for(j=0;j<26;j++){
      if(4*j+7*i==n) goto P;
    }
  }
  goto Q;
  P:
  cout<<"Yes";
  goto R;
  Q:
  cout<<"No";
  R:
  ;
}
  

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

using namespace std;

int main() {
    /* code */
    int N = 0;
    cin >> N;
    vector<int> A(3*N);
    for (size_t i = 0; i < 3*N; i++)
    {
        cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
   
    

    long long ans = 0;
    for (size_t i = 0; i < N; i++)
    {
        ans += A.at(2*i + 1);
        /* code */
    }
    cout << ans << endl;
    
    

    return 0;
}

Measured memory_bytes: 4512
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
const double P = acos( -1 );

int main( void ) {
    double n;
    cin >> n;
    printf("%.6lf %.6lf\n", n * n * P, n * 2 * P ); 
    return 0;
}


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

long gcd(long a, long b){
    if(b != 0)
        return gcd(b, a%b);
    else
        return a;
}

int main(){
    long a, b;
    cin>>a>>b;
    cout << gcd(a, b) << endl;
    return 0;
}

Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int main(){
  int a, b, s = 1, d = 0;
  cin >> a >> b;
	while(true){
      if(s >= b){
        cout << d << '\n';
        break;
      }
      s += a;
      s--;
      d++;
      if(s >= b){
        cout << d << '\n';
        break;
      }
    }
}

Measured memory_bytes: 256
function main(arg) {
	arg = arg.trim().split(' ');
    var min = Math.min(arg[0], arg[1]),
  		max = Math.max(arg[0], arg[1]);
    var out = '';
    for(var i = 0; i < max; i++) {
        out += min
    }
    console.log(out)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main() 
{
    int m, d;
    cin >> m >> d;

    int ans = 0;

    for (int i = 2; i <= m; i++)
    {
        for (int j = 22; j <= d; j++)
        {
            if (j%10 < 2)   continue;
            int tmp = (j/10) * (j%10);
            if (i ==  tmp )  {
                ans++;
            }
        }
        
    }


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

Measured memory_bytes: 256