akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int N;cin>>N;vi a(N);rep(i,N){cin>>a[i];a[i]--;}
  int s=0;
  int ans=0;
  bool ok=false;
  for(int i=0;i<N;i++){
    ans ++;
    if(a[s]==1){
      ok=true;
      break;
    }
    s=a[s];
  }
  if(ok)cout<<ans<<endl;
  else cout<<-1<<endl;
}





Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    ll N; cin >> N;
    int ans = 0;
    FOR(i, 2, 1000010) {
        int cur = 0;
        while (N % i == 0) {
            cur++;
            N /= i;
        }
        FOR(j, 1, 10000) {
            if (cur < j) break;
            ans++; cur -= j;
        }
    }
    if (N > 1) ans++;
    cout << ans << nl;
	
	return 0;
}

Measured memory_bytes: 3672
import numpy as np

N,M = map(int,input().split())

AC = np.array([0]*N)
WA = np.array([0]*N)

for i in range(M):
    p,S = input().split()

    if AC[int(p)-1] ==0 and S == "WA":
       WA[int(p)-1] += 1
    else:
        AC[int(p)-1] = 1

print(sum(AC),sum(AC*WA))


Measured memory_bytes: 16720
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

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

	cout << a + b / 2 << endl;

}

Measured memory_bytes: 256
/** Nguyen Anh Tu **/
#include <bits/stdc++.h>
#define maxn 600005
#define maxc 1000000007
#define MOD 1000000007
#define reset(x) memset(x,0,sizeof(x))
#define task ""
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define F first
#define S second
#define pii pair<int,int>
#define ll long long
#define bit(p,x) ((x>>p) & 1)
#define remain(a,b) (a+b >= MOD) ? (a+b - MOD) : (a+b)
#define mid ((l+r) >> 1)
using namespace std;

int n,k,a[maxn],dp[maxn],t[4 * maxn],ans;

void update(int node, int l, int r, int u, int w){
    if(l == r){
        t[node] = max(t[node], w);
        return;
    }
    if(u <= mid) update(node*2,l,mid,u,w);
    else update(node*2+1,mid+1,r,u,w);
    t[node] = max(t[node*2], t[node*2+1]);
}

int get(int node, int l, int r, int u, int v){
    if(l >= u && r <= v) return t[node];
    if(l > v || r < u) return 0;
    return max(get(node*2,l,mid,u,v),get(node*2+1,mid+1,r,u,v));
}

int main()
{
    ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    cin >> n >> k;
    int MAX = 0;
    for(int i=1; i<=n; ++i){
        cin >> a[i];
        a[i] += 300001;
        MAX = max(MAX, a[i]);
    }
    for(int i=1; i<=n; ++i){
        dp[i] = get(1,1,MAX,a[i]-k, a[i]+k) + 1;
        update(1,1,MAX,a[i],dp[i]);
        ans = max(ans, dp[i]);
    }
    cout << ans;
    return 0;
}


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

int main(){
  string X; cin >> X;
  stack<char> S;
  for(int i=0; i<X.size(); i++){
    if(X[i]=='S'){
      S.push('S');
    }else{
      if(S.empty()==1||S.top()=='T'){
        S.push('T');
      }else{
        S.pop();
      }
    }
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define ll long long
#define ld long double
#define ms(a,v) memset(a,v,sizeof a)
#define pii pair<int, int>
/* * * *   * * *   	* * * */
/* *
 *
 * Author: Hamkor
 *
 * */
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s; cin>>s;
	int n = (int) s.size();
	vector<int> freq(26, 0);
	for (int i=0; i<n; ++i) freq[s[i] - 'a']++;
	for (int i=0; i<26; ++i) if (freq[s[i] - 'a'] > 1 ){
		cout<<"no"<<endl;
		return 0;
	}
	cout<<"yes"<<endl;
	return 0;
}


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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }
/*
#include <bits/stdc++.h>
using namespace std;
 */
struct BIT {
	vector<int> v;
	int n;

	BIT() { init(); }
	BIT(int size) :n(size){ init(); }

	void init() {
		v.clear();
		v.resize(n + 1);
	}

	int sum(int i, int idx = 1) {
//		idx--; idx *= -1; i += idx;
		int ret = 0;
		while (i) {
			ret += v[i];
			i -= i & -i;
		}
		return ret;
	}

	void add(int i, int x, int idx = 1) {
//		idx--; idx *= -1; i += idx;
		while (i <= n) {
			v[i] += x;
			i += i & -i;
		}
	}
};

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

	BIT bit(n);

	while (q--) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		if (a)
			printf("%d\n", bit.sum(c) - bit.sum(b - 1));
		else 
			bit.add(b, c);
	}
}

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

int main(){
    string s;
    cin >> s;
    int m=s.size();
    int n[m+1];
    n[0] = 0;
    for(int i=1; i<=m; i++){
        n[i] = s[i-1]-'0';
    }
    int ans = 0;
    for(int i=m; i>=0; i--){
        if(n[i]<5) ans += n[i];
        else{
            if(n[i] == 5 && n[i-1] < 5){
                ans += n[i];
                continue;
            }
            ans += 10-n[i];
            n[i] = 0;
            for(int j=i-1; j>=0; j--){
                if(n[j] == 9){
                    n[j] = 0;
                }
                else{
                    n[j]++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5252
import sys
n=int(input())

is_same=True
m=10**10
ans=0
for _ in range(n):
    a,b=map(int,input().split())
    if a!=b: is_same=False
    if a>b: m=min(m,b)
    ans+=a

ans-=m
print(ans if not is_same else 0)

Measured memory_bytes: 3064
#include <stdio.h>

int trapezoid(int a, int b, int h) {
  int area = (a + b) * h / 2;
  return area;
}

int main(void) {
  int a, b, h;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &h);
  printf("%d\n", trapezoid(a, b, h));
  return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D; 
  
  if (A + B > C + D) {
  cout << "Left" << endl;
  }
  else if (A + B == C + D) {
  cout << "Balanced" << endl;
  }
  else if (A + B < C + D) {
  cout << "Right" << endl;
  }
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int n, a, b, c;
int l[10];

int dfs(int i, int x, int y, int z){
  if(i==n){
    if(x>0 && y>0 && z>0){
      return abs(x-a)+abs(y-b)+abs(z-c);
    } else {
      return INF;
    }
  }
  int output=dfs(i+1, x, y, z);
  int res1=dfs(i+1, x+l[i], y, z);
  int res2=dfs(i+1, x, y+l[i], z);
  int res3=dfs(i+1, x, y, z+l[i]);
  if(x>0){
    res1+=10;
  }
  if(y>0){
    res2+=10;
  }
  if(z>0){
    res3+=10;
  }
  output=min(output, res1);
  output=min(output, res2);
  output=min(output, res3);
  return output;
}

int main(){
  cin >> n >>a >> b >>c;
  rep(i, n){
    cin >> l[i];
  }
  int ans=dfs(0, 0, 0, 0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3572
a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
p a[gets.to_i-1]

Measured memory_bytes: 1788
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int A, B, C;
  cin>>A>>B>>C;
  cout<<max(C-A+B, 0LL)<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int k,n,maxn,a,b,c;
int main()
{
    scanf("%d%d",&k,&n);
    scanf("%d",&a);
    b=a;maxn=-1;
    for(int i=1;i<n;i++)
    {
        scanf("%d",&c);
        maxn=max(maxn,c-b);
        b=c;
    }
    maxn=max(maxn,a+k-b);
    printf("%d\n",k-maxn);
    return 0;
}


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

S = [list(input()) for i in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        cnt = 0
        for dx in [-1, 0, 1]:
            for dy in [-1, 0, 1]:
                if 0 <= i + dy < H and 0 <= j + dx < W:
                    if S[i+dy][j+dx] == '#':
                        cnt += 1
                else:
                    continue
        S[i][j] = str(cnt)

for k in S:
    print("".join(k))

Measured memory_bytes: 3188
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    L = lmi()
    ans = 2**64-1
    left_sum = 0
    right_sum = sum(L)
    for t in range(n-1):
        left_sum += L[t]
        right_sum -= L[t]
        ans = min(ans, abs(left_sum - right_sum))
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  int a[n+1]={};
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  int ans;

  if((n-1)%(k-1)==0) ans=(n-1)/(k-1);
  else ans=(n-1)/(k-1)+1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define LL long long

using namespace std;
const int N=1e6+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int n,q[N<<1],hd,tl,tg;
char cc[N],ss[N];

int main()
{
    ///
    n=rd();
    scanf("%s%s",cc+1,ss+1);
    hd=n+1,tl=n;
    int ans=0;
    for(int i=n,j=n;i;--i)
    {
	while(j&&(i<j||cc[j]!=ss[i])) --j;
	if(!j){puts("-1");return 0;}
	if(i==j){hd=n+1,tl=n,tg=0;continue;}
	if(hd>tl) q[++tl]=j-tg,q[++tl]=i-tg,ans=max(ans,1);
	else
	{
	    --tg;
	    q[--hd]=j-tg;
	    while(hd<=tl&&q[tl]+tg>=i) --tl;
	    q[++tl]=i-tg;
	    ans=max(ans,tl-hd);
	}
	while(i>j&&ss[i-1]==ss[i]) --i;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs            v.size()
#define ss            s.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii            pair<int, int>
#define int           long long
#define ull           unsigned long long
#define pb            push_back
#define mpp           make_pair
#define Okay          0
#define pi            3.14159

const int inf = 1e8;
const int cont = 1e18;
const int mod = 1e5;
using namespace std;


void solve(){
   int n;
   cin>>n;
   int cnt = 0;
   for(int i=1; i<n; i++){
        cnt += (n-1)/i;
   }
   cout<<cnt<<endl;
}

int32_t main() {
   Fast;
//   int tst;
//   cin>>tst;
//   for(int i=1; i<=tst; i++){
     solve();
//   }
    return Okay;
}



Measured memory_bytes: 3648
import java.util.Scanner;
class Main{
    int H,W,i,r;
    boolean x = true;
    public void solve(){
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt();
        W = sc.nextInt();
        if(H == 0 && W == 0){
            x = false;
        }
        while(x == true){
            for(i = 0; i < H; i++){
                for(r = 0; r < W; r++){
                    if(i%2 == 0 && r%2 == 0 || i%2 == 1 && r%2 == 1){
                        System.out.print("#");
                    }else{
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
            H = sc.nextInt();
            W = sc.nextInt();
            if(H == 0 && W == 0){
                x = false;
            }
        }
    }
    public static void main(String[] args){
        new Main().solve();
    }
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h.at(i);
  
  vector<int> dp(n); // 貰うDP
  dp.at(1) = abs(h.at(0) - h.at(1));
  
  for (int i = 2; i < n; i++) {
    dp.at(i) = min(dp.at(i - 2) + abs(h.at(i) - h.at(i - 2)), dp.at(i - 1) + abs(h.at(i) - h.at(i - 1)));
  }
  
  cout << dp.at(n - 1) << '\n';
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <ctime>
#include <map>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;
ll const mod = 1000000007LL;
int const N = 234567;
ll inv[N], fac[N];

ll ext_gcd(ll a, ll b, ll &x, ll &y){
  ll t,ret;
  if(!b){
    x=1,y=0;return a;
  }
  ret=ext_gcd(b,a%b,x,y);
  t=x,x=y,y=t-a/b*y;
  return ret;
}
ll div(ll a, ll b, ll c) {
  ll x, y; ext_gcd(a,c,x,y);
  return (x*b%c+c)%c;
}
ll cal(ll n, ll m) {
  ll ret = div(fac[n - m], fac[n], mod);
  ret = div(fac[m], ret, mod);
  return ret;
}
ll func(ll n, ll m) {
  return cal(n+m-2,n-1);
}
int main() {
  fac[0]=fac[1]=1;for(int i=2;i<N;++i)fac[i]=fac[i-1]*i%mod;
  int h,w,a,b; cin>>h>>w>>a>>b;
  ll ans=0;
  for(int i=b+1;i<=w;++i){
    ll x=func(i,h-a);
    ll y=func(w-i+1,a);
    ans+=x*y;
    ans%=mod;
  }
  cout<<ans<<endl;
  return 0;
}



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

int main() {
  string s; cin >>s;
  if (s.size()%2) {
    if (s[0]==s[s.size()-1]) cout <<"Second" <<endl;
    else cout <<"First" <<endl;
  } else {
    if (s[0]==s[s.size()-1]) cout <<"First" <<endl;
    else cout <<"Second" <<endl;
  }
  return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a, b, c;
  cin >> a >> b >> c;
  
  if(a == b && a != c) {
    cout << "Yes" << endl;
  }else if(a == c && a != b) {
    cout << "Yes" << endl;
  }else if(b == c && b != a) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 256
import sys
f = sys.stdin

segment =[0b0111111,
0b0000110,
0b1011011,
0b1001111,
0b1100110,
0b1101101,
0b1111101,
0b0100111,
0b1111111,
0b1101111]

while True:
    n = int(f.readline())
    if n == -1:
        break
        
    display = 0
    for i in [int(f.readline()) for _ in range(n)]:
        print(bin(display ^ segment[i])[2:].zfill(7))
        display = segment[i]
    

Measured memory_bytes: 6724
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    string s,t; cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char> ());
    if (s<t) cout << "Yes" << endl; 
    else cout << "No" << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3612
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1e+9;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}




int main() {
  int D,N;
  cin >> D >> N;
  int cnt = 0;
  for(int i = 1; ;i++) {
    int num = i;
    int res = 0;
    while(num) {
      if(num%100 == 0){
	res++;
	num/=100;
      }
      else break;
    }
    if(res == D) cnt++;
    if(cnt == N) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    int n,k;
    cin>>n>>k;
    LL a[n];
    for(int i=0;i<n;i++){cin>>a[i];}
    sort(a,a+n);
    if(k>=n){cout<<0<<endl;}
    else{
        LL ans=0;
        for(int i=0;i<n-k;i++){
            ans=ans+a[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
cnt = [0] * (n*n+1000)
for a in range(1, int(n**0.5)+1):
    for b in range(1, int(n**0.5)+1):
        for c in range(1, int(n**0.5)+1):
            cnt[a*a + b*b + c*c + a*b + b*c + c*a] += 1

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


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

using namespace std;

struct Dish {
  uint64_t A, B;
  Dish(uint64_t A = -1, uint64_t B = -1) : A(A), B(B) {}
  bool operator<(const Dish &rhs) const { return A < rhs.A; }
};

istream& operator>>(istream &is, Dish &dish) {
  is >> dish.A >> dish.B;
  return is;
}

int main()
{
  uint64_t N, T;
  cin >> N >> T;
  
  vector<Dish> dishes(N);
  for (uint64_t n = 0; n < N; ++n) {
    cin >> dishes[n];
  }
  sort(dishes.begin(), dishes.end());
  
  uint64_t A_max = max_element(dishes.begin(), dishes.end())->A;
  
  vector<vector<uint64_t>> dp(N + 1);
  for (uint64_t n = 0; n <= N; ++n) {
    dp[n] = vector<uint64_t>(T + A_max + 1, 0);
  }
  
  for (uint64_t n = 0; n < N; ++n) {
    for (uint64_t t = 0; t < T; ++t) {
      // n番目の料理を食べない
      dp[n + 1][t] = max(dp[n + 1][t], dp[n][t]);
      
      // n番目の料理を食べる
      dp[n + 1][t + dishes[n].A] = max(dp[n + 1][t + dishes[n].A], dp[n][t] + dishes[n].B);
    }
  }
  
  uint64_t max_value = 0;
  for (uint64_t n = 0; n <= N; ++n) {
    max_value = max(max_value, *max_element(dp[n].begin(), dp[n].end()));
  }
  cout << max_value << endl;
  
  return 0;
}

Measured memory_bytes: 141056
#include<bits/stdc++.h>
using namespace std;
#define y1 A2Dalek
#define y0 Cyberman
#define yn RoseTyler
#define j1 JackHarkness
#define fs first
#define sd second
const int N=300;
const int oo=1e9+5;
int du[]={-1,0,0,1};
int dv[]={0,-1,1,0};
const long long mod=1e9+7;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
long long sqr(long long x) {return x*x;}
int getbit(int state, int i) {return ((state>>i)&1);}

int n,m,res,f[N+5][N+5][N+5];
bool ok[N+5][N+5][N+5];
vector<ii> q[N+5];
void khoitao()
{
    for (int i=0;i<=n;i++) for (int j=0;j<=i;j++) for (int k=0;k<=j;k++)
    {
        ok[i][j][k]=true;
        for (int h=0;h<q[i].size();h++)
        {
            int vt=q[i][h].fs,dem=1;
            if (vt<=j) dem++;
            if (vt<=k) dem++;
            if (dem!=q[i][h].sd) {ok[i][j][k]=false; break;}
        }
    }
}
int main()
{
	//freopen("RGB Sequence.inp","r",stdin);
	//freopen("RGB Sequence.out","w",stdout);
	ios_base::sync_with_stdio(false);
    cin>>n>>m;
    for (int i=1;i<=m;i++)
    {
        int l,r,x;
        cin>>l>>r>>x;
        q[r].push_back(ii(l,x));
    }
    khoitao();
    f[0][0][0]=1;
    for (int i=0;i<=n;i++) for (int j=0;j<=n;j++) for (int k=0;k<=n;k++)
    {
        if (i==j && i) {f[i][j][k]=0; continue;}
        if (i==k && i) {f[i][j][k]=0; continue;}
        if (j==k && j) {f[i][j][k]=0; continue;}
        int u=i, v=j, z=k;
        if (u<v) swap(u,v); if (u<z) swap(u,z); if (v<z) swap(v,z);
        if (!ok[u][v][z]) {f[i][j][k]=0; continue;}
        if (u==n) {res=(res+f[i][j][k])%mod; continue;}
        f[u+1][j][k]=(f[u+1][j][k]+f[i][j][k])%mod;
        f[i][u+1][k]=(f[i][u+1][k]+f[i][j][k])%mod;
        f[i][j][u+1]=(f[i][j][u+1]+f[i][j][k])%mod;
    }
    cout<<res;
	return 0;
}


Measured memory_bytes: 135552
N,X,Y=map(x->parse(Int,x),split(readline()," "))
c=zeros(Int,N-1)
for i in 1:(N-1)
  for j in (i+1):N
    t1=abs(i-X)+abs(j-Y)+1
    t2=j-i
    c[ (t1>t2) ? t2 : t1 ]+=1
  end
end
for i in c
  println(i)
end

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

using namespace std;

int main(void) {
        int W, h, m, s;
        cin >> W;
       
        h = W / 3600;
        m = (W % 3600) / 60;
        s = (W % 3600) % 60;
        
        cout << h << ":" << m << ":" << s << endl;
        return 0;
}

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

int main()
{
  	string a;
  	cin>>a;
  	int m[26] = {0};
  	for(int i = 0; i < a.length(); i++)
    	m[a[i]-'a']++;
  	int flag = 0;
  	for(int i = 0; i < 26; i++)
    {
    	if(m[i] > 1)
        {
        	flag = 1;
          	break;
        }
    }
  	if(flag == 1)
      	cout<<"no";
  	else
      	cout<<"yes";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005,M=1000020,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int cnt,n,m,S,T,ans[N],ansu[N],h[N];
vector<int> a[N],b[N];
int fir[N],firr[N],siz;
struct edge{int u,v,w,nex;}e[M];
void add(int u,int v,int w){
	e[++siz]=(edge){u,v,w,fir[u]};fir[u]=siz;
	e[++siz]=(edge){v,u,0,fir[v]};fir[v]=siz;
}
int dist[N],que[N];
void dec(int x,int fl){e[x].w-=fl;e[x^1].w+=fl;}
bool bfs(){
	memset(dist,0x3f,4*(cnt+1));
	int l=1,r=1;que[l]=S;dist[S]=0;
	while (l<=r){
		int x=que[l];
		for (int i=fir[x];i;i=e[i].nex)
		if ((e[i].w)&&(dist[e[i].v]>dist[x]+1)){
			que[++r]=e[i].v;
			dist[e[i].v]=dist[x]+1;
		}
		l++;
	}
	return dist[T]!=inf;
}
int dfs(int x,int flow,int &T){
	if (x==T) return flow;
	int fl=0,t=0;
	for (int i=firr[x];i;i=e[i].nex)
	if (e[i].w&&(dist[e[i].v]>dist[x])){
		t=dfs(e[i].v,min(flow-fl,e[i].w),T);
		dec(i,t);fl+=t;
		if (fl==flow) {firr[x]=i;return fl;}
	}
	firr[x]=0;
	return fl;
}
int dinic(){
	int flow=0;
	while (bfs()){
		for (int i=0;i<=cnt;i++) firr[i]=fir[i];
		flow+=dfs(S,inf,T);
		//cerr<<flow<<endl;
	}
	return flow;
}
void check(int x){
	h[x]=1;
	for (auto i : b[x])
	if (!h[ans[i]]){ansu[i]=x;check(ans[i]);}
}
int main(){
//	freopen("1.in","r",stdin);
	siz=1;
	n=read();S=1,T=cnt=n*2;
	for (int i=2;i<=n;i++) add(S,i,1);
	for (int i=1;i<n;i++) add(i+n,T,1);
	for (int i=1;i<n;i++){
		int m=read();
		while (m--){
			int x=read();a[i].push_back(x);
			b[x].push_back(i);
			if (x!=1) add(x,i+n,1);
		}
	}
	if (dinic()!=n-1){puts("-1");return 0;}
	for (int i=2;i<=siz;i++)
	if ((!e[i].w)&&(e[i].u>=1)&&(e[i].u<=n)&&(e[i].v>n)&&(e[i].v<n+n)) ans[e[i].v-n]=e[i].u;
	check(1);
	for (int i=1;i<=n;i++) if (!h[i]) {puts("-1");return 0;}
	for (int i=1;i<n;i++) printf("%d %d\n",ansu[i],ans[i]);
	return 0;
}

Measured memory_bytes: 42368
#include <cstdio>
#include <iostream>

using namespace std;

struct dice{
	int q1,q2,q3,q4,q5,q6;
};

void mN(dice &d){
	int tmp=d.q1;
	d.q1=d.q2;
	d.q2=d.q6;
	d.q6=d.q5;
	d.q5=tmp;
}

void mE(dice &d){
	int tmp=d.q1;
	d.q1=d.q4;
	d.q4=d.q6;
	d.q6=d.q3;
	d.q3=tmp;
}

void spin(dice &d){
	int tmp=d.q2;
	d.q2=d.q3;
	d.q3=d.q5;
	d.q5=d.q4;
	d.q4=tmp;
}

bool isSame(dice y, dice z){
	bool flag = false;

	for(int i=0; i<4; ++i){
		for(int j=0; j<4; ++j){
			if(y.q1==z.q1 && y.q2==z.q2 && y.q3==z.q3 && y.q4==z.q4 && y.q5==z.q5 && y.q6==z.q6) {
				flag = true;
				break;
			}
			spin(y);	
		}
		if(flag) break;
		mN(y);
	}
	
	mE(y);
	
	for(int i=0; i<4; ++i){
		for(int j=0; j<4; ++j){		
			if(y.q1==z.q1 && y.q2==z.q2 && y.q3==z.q3 && y.q4==z.q4 && y.q5==z.q5 && y.q6==z.q6) {
				flag = true;
				break;
			}
			spin(y);	
		}
		if(flag) break;
		mN(y);
	}	
			
	return flag;
}

int main(){
	dice a[100];
	int n;
	bool ans=false;
	
	scanf(" %d", &n);
	
	for(int i=0; i<n; ++i)
		scanf(" %d %d %d %d %d %d", &a[i].q1, &a[i].q2, &a[i].q3, &a[i].q4, &a[i].q5, &a[i].q6);
		
	for(int i=0; i<n-1; ++i){
		for(int j=i+1; j<n; ++j){
			ans=isSame(a[i], a[j]);
			if(ans) break;
		}
		if(ans) break;
	}
	
	if(ans) printf("No\n");
	else printf("Yes\n");
		
	return 0;
}

Measured memory_bytes: 1172
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    string s;
    cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad" << endl;
    else cout << "Good" << endl;

    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define pb push_back
//#define int long long
#define mod 1000000007
#define fi first
#define se second
#define ll long long
#define scan() ll n; cin>>n ; ll a[n]; for(ll i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
using namespace std;
typedef vector<int>vi ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<ll,ll> pll ;
int main()
{
	fast;
	ll a,b,c;
  	cin>>a>>b>>c;
  	cout<<c<<" "<<a<<" "<<b;
	return 0;
}

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

using namespace std;
using ll = long long;
constexpr ll mod = 1e9+7;
constexpr ll md = mod;
constexpr ll inf = 1e15;
int main(){
    string s,t;
    cin>>s>>t;
    map<char,char> m;
    map<char,char> rev;
    bool ok = true;
    for(int i=0;i<(int)s.size();++i){
        if(m.count(s[i])){
            if(m[s[i]] != t[i]){ok=false;break;}
        }
        if(rev.count(t[i])){
            if(rev[t[i]] != s[i]){ok = false; break;}
        }
        m[s[i]] = t[i];
        rev[t[i]] = s[i];
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 776
// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
	ifstream ifs("in.txt");
	cin.rdbuf(ifs.rdbuf());
#endif
	ll N, K; cin >> N >> K; vector<ll> A(N); FOR(i, N) cin >> A[i];
	vector<ll> B(A); FOR(i, N) if (B[i] < 0) B[i] = 0;

	auto getRangeSum = [](const vector<ll>& A, ll L, ll R) {
		return A[R + 1] - A[L];
	};

	vector<ll> Accumu(B); Accumu.insert(Accumu.begin(), { 0LL });
	FOR(i, N) Accumu[i + 1] += Accumu[i];

	vector<ll> Accumu_Raw(A); Accumu_Raw.insert(Accumu_Raw.begin(), { 0LL });
	FOR(i, N) Accumu_Raw[i + 1] += Accumu_Raw[i];
	ll ans = 0;
	
	// White
	chmax(ans, getRangeSum(Accumu, K, N-1));
	FOR(_i, N - K) {
		auto drop_startE = _i;
		auto newend_E = _i + K;
		chmax(ans, getRangeSum(Accumu, 0, N-1) - getRangeSum(Accumu, drop_startE+1, newend_E)) ;
	}


	//ll KSum = accumulate(A.begin(), A.begin() + K, 0);
	chmax(ans, getRangeSum(Accumu, K, N - 1) + getRangeSum(Accumu_Raw, 0, K - 1));
	FOR(_i, N - K) {
		auto drop_startE = _i;
		auto newend_E = _i + K;
		chmax(ans, getRangeSum(Accumu, 0, N - 1) - getRangeSum(Accumu, drop_startE + 1, newend_E) + getRangeSum(Accumu_Raw, drop_startE+1, newend_E)); 
	}

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


Measured memory_bytes: 4208
#include <cstdio>

using namespace std;

long long c[3001][3001];
long long dp[3001][3001];

long long powmod(long long x, long long y, long long m) {
    long long ans = 1;
    
    while (y > 0) {
        if (y & 1) ans = ans * x % m;
        x = x * x % m;
        y >>= 1;
    }
    
    return ans;
}

int main() {
    int n, m, f = -1, i, j, k;
    long long ans;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i <= n; i++) {
        c[i][0] = c[i][i] = 1;
        for (j = 1; j < i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % m;
    }
    
    ans = powmod(2, powmod(2, n, m - 1), m);
    
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= i; j++) {
            if (j == 1) {
                dp[i][j] = powmod(2, i, m) - 1;
            } else {
                dp[i][j] = (j + 1) * dp[i - 1][j] + dp[i - 1][j - 1];
                dp[i][j] %= m;
            }
        }
    }
    
    for (i = 1; i <= n; i++, f *= -1) {
        long long x = 1, y = powmod(2, n - i, m);
        
        for (j = 1; j <= i; j++) {
            x += dp[i][j] * powmod(y, j, m) % m;
            if (x >= m) x -= m;
        }
        
        x = x * c[n][i] % m;
        x = x * powmod(2, powmod(2, n - i, m - 1), m) % m;
        
        ans += x * f;
        if (ans >= m) ans -= m;
        if (ans < 0) ans += m;
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 139264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;

//while(c){
//    total += c%10;
//    c/=10;
//}

int main() {
    int x,y,ans = 0; cin >> x >> y;
    for(int i = x;i <= y;i++){
        string a = to_string(i);
        string b = a;
        reverse(b.begin(),b.end());
        if(a == b){
            ans++;
        }
    }
    cout << ans;
}




Measured memory_bytes: 256
def main():
    n,x,y=map(int,input().split())
    dist=[0]*(n-1)
    x-=1
    y-=1
    for i in range(n-1):
        for j in range(i+1,n):
            d=j-i
            dist[min(d,abs(x-i)+abs(y-j)+1)-1]+=1

    for i in dist:
        print(i)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, m;
	cin >> n >> m;
	vector<string> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	auto code = [&](int x, int y) {
		return m * x + y;
	};
	vector<vector<int>> dp(n * m, vector<int>(n * m, inf));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			dp[code(i, j)][code(i, j)] = 0;
			if (a[i][j] == '#') {
				continue;
			}
			if (i + 1 < n && a[i + 1][j] == '.') {
				dp[code(i, j)][code(i + 1, j)] = 1;
				dp[code(i + 1, j)][code(i, j)] = 1;
			}
			if (j + 1 < m && a[i][j + 1] == '.') {
				dp[code(i, j)][code(i, j + 1)] = 1;
				dp[code(i, j + 1)][code(i, j)] = 1;
			}
		}
	}
	for (int k = 0; k < n * m; ++k) {
		for (int i = 0; i < n * m; ++i) {
			for (int j = 0; j < n * m; ++j) {
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}
	int mx = 0;
	for (int i = 0; i < n * m; ++i) {
		for (int j = 0; j < n * m; ++j) {
			if (dp[i][j] != inf) {
				mx = max(mx, dp[i][j]);
			}
		}
	}
	cout << mx << '\n';
 	return 0;
}


Measured memory_bytes: 896
import java.io.*;
import java.util.Arrays;
   
class Main{
   
static final int INF=Integer.MAX_VALUE/2;
static final PrintWriter out=new PrintWriter(System.out);
   
   
static class Edge{
int from;
int to;
int cost;
Edge(int from,int to,int cost){
this.from=from; this.to=to; this.cost=cost;
}
}
   
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int v=Integer.parseInt(line.split(" ")[0]);
int e=Integer.parseInt(line.split(" ")[1]);
int r=Integer.parseInt(line.split(" ")[2]);
Edge[] es=new Edge[e];
int[] d=new int[v];
for(int i=0;i<e;i++){
line=br.readLine();
int s=Integer.parseInt(line.split(" ")[0]);
int t=Integer.parseInt(line.split(" ")[1]);
int c=Integer.parseInt(line.split(" ")[2]);
es[i]=new Edge(s,t,c);
}
if(BellmanFord(v,e,r,es,d)){
out.println("NEGATIVE CYCLE");
}
else{
for(int i=0;i<v;i++){
out.println((d[i]==INF)?"INF":d[i]);
}
}
out.flush();
}
}
   
private static boolean BellmanFord(int v,int ee,int r,Edge[] es,int[] d){
Arrays.fill(d,INF);
d[r]=0;
for(int i=0;i<v;i++){
boolean update=false;
for(int j=0;j<ee;j++){
Edge e=es[j];
if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
d[e.to]=d[e.from]+e.cost;
update=true;
if(i==v-1) return true;
}
}
if(!update){
break;
}
}
return false;
}
}

Measured memory_bytes: 41076
#include <bits/stdc++.h>
using namespace std;
int n;
int dif; 
vector<pair<int,int> > L,R;
bool check(vector<pair<int,int> > v){
	int l=0;
	for(int i=0;i<v.size();++i){
		pair<int,int> p=v[i];
		int dif=l+p.first;
		if(dif<0){
			return 0;
		}
		l+=p.second;
	}
	return 1;
} 
int main(){
	cin>>n;
	for(int i=0;i<n;++i){
		string s;
		cin>>s;
		int l=0,minl=1e9;
		for(int k=0;k<s.size();++k){
			l+=(s[k]=='(')?1:-1;
			minl=min(minl,l);
		}
		dif+=l;
		if(l>0){
			L.push_back({minl,l});
		}
		else{
			R.push_back({minl-l,-l});
		}
	}
	sort(L.rbegin(),L.rend());
	sort(R.rbegin(),R.rend());
	if(dif==0&&check(L)&&check(R)){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
	return 0;
} 

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

typedef unsigned long long ll;

int main(int argc, char *argv[]) {
  ll l, r;
  cin >> l >> r;

  ll ans = 2019;
  r = min(l+2019, r);
  for (ll i = l; i <= r; ++i) {
    for (ll j = i+1; j <= r; ++j) {
      ans = min(ans, i*j%2019);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int line[31], w, n, i;
	
	for (i=0; i<31; i++) {
		line[i] = i+1;
	}
	scanf("%d", &w); line[w] = -1;
	scanf("%d", &n);
	for (i=0; i<n; i++) {
		int a, b, temp;
		scanf("%d,%d", &a, &b);
		temp = line[a-1];
		line[a-1] = line[b-1];
		line[b-1] = temp;
	}
	for (i=0; i<w; i++) printf("%d\n", line[i]);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);

  for (int i = 0; i < n; i++){
    cin >> v.at(i);
  }
  for (int i = 0; i < n; i++){
    cin >> c.at(i);
  }

  int ans = 0;
  for (int i = 0; i < n; i++){
    if (v.at(i)>c.at(i)){
      ans += v.at(i)-c.at(i);
    }
  }
  cout << ans << endl;
}

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

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

int f(int x) {
	if(x == 1) return 300000;
	if(x == 2) return 200000;
	if(x == 3) return 100000;
	return 0;
}

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

	int ans = f(n) + f(m);

	if(n == 1 && m == 1) ans += 400000;
	printf("%d\n", ans);

    return 0;
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	string s;
	cin >> s;
	int a = 0 ,  z = sz(s) - 1;
	while(s[a] != 'A')++a;
	while(s[z] != 'Z')--z;
	die(z - a + 1);

	return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;


#define MAX_N 10000
struct UnionFind{
    int par[MAX_N]; 
    void init(int n){
        for (int i=0;i<n;i++) par[i] = i;
    } 
    int find(int x){
        if (x==par[x]) return (x);
        return (par[x]=find(par[x]));
    }
    void unite(int x, int y){
        x=find(x);y=find(y);       
        if(x==y) return;
        par[x] = y;
    } 
    bool same(int x, int y){
        return (find(x) == find(y));
    } 
};

int main(){
    int n,q,c,x,y;
    UnionFind uf;
    cin>>n>>q;
    uf.init(n);
    rep(i,q){
        cin>>c>>x>>y;
        if(c==0) uf.unite(x,y);
        else{
            if(uf.same(x,y)) cout<<1<<endl;
            else cout<<0<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3192
#include <stdio.h>

constexpr unsigned int MAX_INPUT = 5e5;
char Input[MAX_INPUT];
char* input = Input;

template <class Integer = long long int>
inline Integer get(void){
    Integer res = 0;
    if(*input == '-'){
        while(*(++input) >= '0'){ res = 10 * res + *input - '0'; }
        return -res;
    }
    do{ res = 10 * res + *(input++) - '0'; } while(*input >= '0');
    return res;
}

struct circle{
    long long int x, y;
    int radius;
    circle(void):x(),y(),radius(){}
    static double distance(const long long int dx, const long long int dy){
        return __builtin_sqrt(dx * dx + dy * dy);
    }
    inline void in0(void){x = get(); input++; y = get(); input++;}
    inline void in(void){ x = get(); input++; y = get(); input++; radius = get<int>(); input++;}
    inline double distance(const circle& other){
        double d = distance(x - other.x, y - other.y) - (radius + other.radius);
        return (d < 0) ? 0 : d;
    }
};

inline void chmin(double& v, const double val){ if(v > val) v = val; }

using uint = unsigned int;
constexpr uint MAX_N = 1000;
constexpr double inf = 3e18 + 3e17 + 4e16;
circle Point[MAX_N + 2];
bool visited[MAX_N + 2];
double dist[MAX_N + 2];

int main(void){
    fread(Input, sizeof(char), MAX_INPUT, stdin);

    Point[0].in0(); Point[1].in0();

    uint n = get(); input++;
    Point[++n] = Point[1]; dist[n] = inf;

    for(uint i = 1; i < n; ++i) { Point[i].in(); dist[i] = inf;}

    for(uint _ = 0, s = 0; _ < n; ++_){
        double min = inf; uint nearest = 0; visited[s] = true;
        for(uint v = 1; v <= n; ++v) if(not visited[v]){
            const double d = Point[s].distance(Point[v]);
            chmin(dist[v], dist[s] + d);
            if(min > dist[v]){ min = dist[v]; nearest = v; }
        }
        s = nearest;
        if(s == n) break;
    }
    printf("%.16lf\n", dist[n]);

    return 0;
}


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

int main() {
    int A,B;
    cin >> A >> B;
    if (A == B) {
        cout << "Draw" << endl;
    }
    else if (A == 1 || (A != 1 && B!= 1 && A > B)) {
        cout << "Alice" << endl;
    }
    else {
        cout << "Bob" << endl;
    }
}



Measured memory_bytes: 3604
n = int(input())
a = list(map(int,input().split()))
flg = True

for i in range(n-2, -1, -1):
    if n == 1:
        break
    if a[i] - a[i+1] >= 2:
        flg = False
        break
    elif a[i] - a[i+1] == 1:
        a[i] -= 1
print('Yes') if flg else print('No')

Measured memory_bytes: 85304