akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

string s;
cin >> s;

int now = 0;
if(s[0] == 'A'){
    now++;
    s[0] = 'a';
}

int cnt = 0;
for(int i = 2; i <= s.size()-2 ; i++){
    if(s[i] == 'C') cnt++;
}
if(cnt == 1){
    now++;
    for(int i = 2; i <= s.size()-2 ; i++) s[i] = 'a';
}

int cnt2 = 0;
rep(i,s.size()){
    if(int(s[i]) >= 97 && int(s[i]) <= 122) cnt2++;
}
if(cnt2 == s.size()) now++;
if(now == 3) puts("AC");
else puts("WA");


return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c=0, n, k;
string s,t;
//cout<<<<endl;


int main()
{
	cin >> a >> b;
	if (a <= 0 && b >= 0)
	{
		cout << "Zero" << endl;
	}
	else
		cout << ((b < 0 && (b - a) % 2 == 0) ? "Negative" : "Positive");
	cout << endl;
	
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] ATGC = {'A','T','G','C'};
		String s = sc.next();
		int maxlen = 0;
		int len = 0;
		for(int i = 0;i < s.length();i ++) {
			char c = s.charAt(i);
			boolean ATGCis = false;
			for(int k = 0;k < 4;k ++) {
				if(c == ATGC[k]) ATGCis = true;
			}
			if(ATGCis == false) {
				if(maxlen < len) {maxlen = len; len = 0;}
				else len = 0;
			}
			else {
				if(i == s.length() - 1) {
					if(maxlen < (len + 1)) maxlen = len + 1;
				}
				else len ++;
			}
		}
		System.out.println(maxlen);
	}
}

Measured memory_bytes: 25300
k, n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
maxx = 0
key = 0
for i in range(0, n):
  if i == n-1:
    key = (k + a[0]) - a[i]
  else:
    key = a[i+1] - a[i]
  if maxx < key:
    maxx = key
print(k - maxx)

Measured memory_bytes: 26444
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n)cin >> vec[i];

    int ans = 1e9;

    reps(i,1,101){
        int total = 0;
        rep(j,n){
            total += (vec[j]-i)*(vec[j]-i);
        }
        ans = min(ans,total);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int n,t,a;
	cin>>n>>t>>a;
	double ans=1000;
	int nas=0;
	int h;
	for (int i=0;i<n;i++) {
		cin>>h;
		if (ans>abs(t-h*0.006-a)) {
			ans=abs(t-h*0.006-a);
			nas=i+1;
		}
	}
	cout<<nas<< endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<functional>
#include<cstdio>
using namespace std;

int main(void){
	int sci[4], soc[2];
	scanf("%d%d%d%d%d%d", sci+0, sci+1, sci+2, sci+3, soc+0, soc+1);
	sort(sci, sci+4, greater<int>());
	printf("%d\n", sci[0]+sci[1]+sci[2]+max(soc[0], soc[1]));
	return(0);
}


Measured memory_bytes: 2764
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  char s[1000];
  for(int i=1;i<=n;i++)
  {
    cin>>s[i];
  }
  s[k]=s[k]+' ';
  for(int i=1;i<=n;i++)
  {
    cout<<s[i];
  }
}

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

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

using ll = long long;
#define INF 1e9


int main(){
  int N, M;
  cin >> N >> M;
  int ans = INF;
  
  for(int i = 1; i <= (M+1)/2; i++){
    if(M % i == 0){
      if(i >= N){
        ans = min(ans, i);
      }
      else{
        int m = M/i;
        if(m >= N){
          ans = min(ans, M / i);
        }
      }
    }
  }
  cout << M / ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

    int n = 5;
    for (int i = 0; i < n; i++)
    {
        int p;
        cin >> p;
        if (p == 0)
            cout << i + 1 << endl;
    }
}

Measured memory_bytes: 3604
n,m = map(int,input().split())
div = []
for i in range(1,int(m**0.5)+1):
    if m%i == 0:
        div.append(i)
        div.append(m//i)
div.sort(reverse=True)
for x in div:
    if m//x >= n:
        print(x)
        break

Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define all(x) x.begin(),x.end()
#define rep(i,m,n) for(int i=m ; i<n ; i++)
#define forr(i,m,n) for(int i=m ; i<=n ; i++)
#define clr(v,val) memset(v,val,sizeof(v))
#define endl '\n'
#define pb push_back
#define pff push_front
#define re return
const int N = 1e5 + 5;
const ll mod=int(1e9)+7;
using namespace std;
int main()
{
    IO;
    int n,m; cin>>n>>m;
    if(m>=n)
        cout<<"Yes";
    else
        cout<<"No";




}


Measured memory_bytes: 256
s = str(input())
t = str(input())
lst = []
i= 0
for ss in range(len(s)-len(t)+1):
  flg = 1
  i= 0
  for tt in range(len(t)):
    now = ss + tt
    if s[now] == t[tt] or s[now] == '?':
      pass
    else:
      flg = 0
  if flg:
    ns = list(s)
    ns[ss:now+1] = list(t)
    lst.append(("").join(ns))
if lst:
  lst = [_.replace('?','a') for _ in lst]
  lst.sort()
  print(lst[0])

else:
  print('UNRESTORABLE')


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

class UnionFind {
public:
    vector<int> parent;  //親ノード
    vector<int> Siz;  //集合の大きさ

    // コンストラクタ
    UnionFind(int n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(int n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    int root(int x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {

        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }

        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }

        Siz[x] += Siz[y];
        parent[y] = x;
    }

    // xとyが同じ集合に属するかどうか
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    int size(int x) {
        return Siz[root(x)];
    }
};

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

    UnionFind Road(n), Rail(n);

    rep(i, k) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        Road.unite(p, q);
    }

    rep(i, l) {
        int r, s;
        cin >> r >> s;
        r--;
        s--;
        Rail.unite(r, s);
    }

    map<pair<int, int>, int> mp;

    rep(i, n) {
        mp[make_pair(Road.root(i), Rail.root(i))]++;
    }

    rep(i, n) {
        cout << mp[make_pair(Road.root(i), Rail.root(i))] << " ";
    }

    cout << endl;
    return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> f(N, vector<int>()); //from
    vector<vector<int>> g(N, vector<int>()); //行先
    vector<int> h(N, 0); //入次数
    int x, y;
    for (int i = 0; i < M; i++) {
        cin >> x >> y;
        f.at(y - 1).push_back(x - 1);
        g.at(x - 1).push_back(y - 1);
        h.at(y - 1)++;
    }
    vector<int> L; //トポロジカルソートした列
    stack<int> S; //入力のない頂点集合
    for (int i = 0; i < N; i++) {
        if (h.at(i) == 0) {
            S.push(i);
        }
    }
    int v;
    while (!S.empty()) {
        v = S.top();
        S.pop();
        L.push_back(v);
        for (int i = 0; i < g.at(v).size(); i++) {
            int j = g.at(v).at(i);
            h.at(j)--;
            if (h.at(j) == 0) {
                S.push(j);
            }
        }
    }
    vector<int> dp(N); //dp.at(i):iで終わる最長の長さ
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int v = L.at(i);
        int l = 0;
        for (int j = 0; j < f.at(v).size(); j++) {
            l = max(l, dp.at(f.at(v).at(j)) + 1);
        }
        dp.at(v) = l;
        ans = max(ans, l);
    }
    cout << ans << endl;
}

Measured memory_bytes: 12540
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};

int main(void) {
    int n;
    bool flag=true;
    string s;

    cin>>n>>s;

    if(n%2!=0){
       flag=false; 
    }
    FOR(i,1,n/2){
        if(s[i-1]!=s[i-1+(n/2)]){
            flag=false;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int a=s.size();
	char s1=s[a-1];
	if(s1=='2'||s1=='4'||s1=='5'||s1=='7'||s1=='9')
	cout<<"hon";
	else
	if(s1=='0'||s1=='1'||s1=='6'||s1=='8')
	cout<<"pon";
	else
	cout<<"bon";
} 

Measured memory_bytes: 3624
ans=n=int(input())
s=input()
a=[0]
for i in s:
    if i==".":a+=[a[-1]+1]
    else:a+=[a[-1]]
w=s.count(".")
for i in range(n+1):
    ans=min(ans,i-a[i]+w-a[i])
print(ans)

Measured memory_bytes: 16960
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

long long int dp[9030][3030], pre;

int N, T;
int A[3030], B[3030];

vector<pair<int, int> > V;

int main(void) {

	cin >> N >> T;

	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
		V.push_back(make_pair(A[i], B[i]));
	}

	sort(V.begin(), V.end());

	long long int ans = 0;

	for (int i = 1; i <= N; i++) {
		for (int t = 0; t <= 6000; t++) { dp[t][i] = dp[t][i - 1]; }
		for (int t = 0; t < T; t++) {
			int a = V[i - 1].first;
			int b = V[i - 1].second;
			dp[t + a][i] = max(dp[t + a][i], dp[t][i-1] + b);
			//dp[t][i] = max(dp[t][i], dp[t][i - 1]);
		}
	}

	for (int t = 0; t <= 6000; t++) {
		ans = max(ans, dp[t][N]);
	}

	
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 143616
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;

int main() {

	Int n, k;
	cin >> n >> k;

	string s;
	cin >> s;

	if (s[k - 1] == 'A')s[k - 1] = 'a';
	if (s[k - 1] == 'B')s[k - 1] = 'b';
	if (s[k - 1] == 'C')s[k - 1] = 'c';

	cout << s << endl;
}

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

using namespace std;

int n, a[32] = {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};

int main(){
	cin >> n;
	cout << a[n-1] << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
from collections import deque


def main():
	n = int(input())

	def label(a, b):
		if a > b:
			a, b = b, a
		return (a - 1) * (2 * n - a) // 2 + b - a - 1

	m = n * (n - 1) // 2
	g = [[] for _ in range(m)]
	deg = [0] * m
	for i in range(1, n + 1):
		l = list(map(int, input().split()))
		for x, y in zip(l, l[1:]):
			t = label(i, y)
			g[label(i, x)].append(t)
			deg[t] += 1

	depth = [None] * m
	q = deque()
	ans = 1
	for i, d in enumerate(deg):
		if not d:
			depth[i] = 1
			q.append(i)
	while q:
		cur = q.popleft()
		for nxt in g[cur]:
			deg[nxt] -= 1
			if not deg[nxt]:
				depth[nxt] = depth[cur] + 1
				if ans < depth[nxt]:
					ans = depth[nxt]
				q.append(nxt)
	print(ans if all(depth) else -1)

if __name__ == "__main__":
	main()

Measured memory_bytes: 117704
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    k = I()
    a, b = LI()
    for p in range(a, b+1):
        if p % k == 0:
            print('OK')
            return
    print('NG')

main()



Measured memory_bytes: 10916
class weight_union_find(object):
    def __init__(self, n):
        self.par = [-1 for i in range(n)]
        self.weight_diff = [0 for i in range(n)]
        self.rank = [1 for i in range(n)]
    
    def root(self, ind):
        if self.par[ind] < 0:
            return ind
        else:
            r = self.root(self.par[ind])
            self.weight_diff[ind] += self.weight_diff[self.par[ind]]
            self.par[ind] = r
            return r

    def unite(self, ind1, ind2, w):
        root1 = self.root(ind1)
        root2 = self.root(ind2)
        if root1 == root2:
            # 重みが違う==解無し
            # print(root1, root2, self.weight_diff[ind1], self.weight_diff[ind2], w)
            if -(self.weight_diff[ind1] - self.weight_diff[ind2]) == w:
                return True
            else:
                return False
        else:
            #swap
            if self.rank[root1] == self.rank[root2]:
                self.rank[root1] += 1
            if self.rank[root1] < self.rank[root2]:
                root1, root2 = root2, root1
                ind1, ind2 = ind2, ind1
                w *= -1
            self.par[root1] += self.par[root2]
            self.par[root2] = root1
            self.weight_diff[root2] = w + self.weight_diff[ind1] - self.weight_diff[ind2]
            return True



n, m = list(map(int, input().split()))
query = []
for i in range(m):
    query.append(list(map(int, input().split())))
uf = weight_union_find(n)
for l, r, d in query:
    if not uf.unite(l-1, r-1, d):
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 58496
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A[][] = new int[2][N];
        long ans = 0;
        int tmp=0;
        long result0 = 0;
        long result1 = 0;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < N; j++) {
                A[i][j] = sc.nextInt();
            }
        }
            for(int i=0;i<N;i++){
                int j=0;
                tmp=0;
                while(j<=i){
                  tmp+=A[0][j];
                  j++;
                }
                int k=i;
                while(k<N){
                    tmp+=A[1][k];
                    k++;
                    
                }
                    ans=Math.max(ans,tmp);
                }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <stdio.h>
int main(void)
{
    int n;
    int a;
    scanf("%d", &n);
    n=n+1;
    for (a=1;a<n;a++)
    {
        if (a%3==0)
        {
            printf(" %d", a);
        }
        else if (a%10==3)
        {
            printf(" %d", a);
        }
        else if ((a/10)%10==3)
        {
            printf(" %d", a);
        }
        else if ((a/100)%10==3)
        {
            printf(" %d", a);
        }
        else if (a/10==3)
        {
            printf(" %d", a);
        }
        else if (a/100==3)
        {
            printf(" %d", a);
        }
        else if (a/1000==3)
        {
            printf(" %d", a);
        }
 
    }
    printf("\n");
    return 0;
}


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

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

    vector<int> c(n);

    vector<int> ti(n);

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

        cin>>c[i]>>ti[i];
    }

    int ans =100000;

    bool check = false;

    for(int i=0; i<n; i++) {
        
        if(ti[i] <= t ){ 
            
        ans = min(ans,c[i]);
        
        check = true;
        
        }

    }

    if(check) cout<<ans<<endl;

    else cout<<"TLE"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

template<class T> inline bool cmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool cmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll MAXN=1e5+5;
const ll MAXLG=__lg(MAXN)+2;

ll n,k;
ll dp[104][MAXN],a[MAXN];

/********** Good Luck :) **********/
int main()
{
    IOS();
    cin >> n >> k;
    REP (i,n) {
        cin >> a[i];
    }

    REP (i,a[0]+1) {
        dp[0][i] = 1;
    }

    REP1 (i,n-1) {
        deque<pii> dq;
        ll sum = 0;
        REP (j,k+1) {
            while (dq.size() && j- dq.front().X > a[i]){
                sum -= dq.front().Y;
                while (sum < 0) {
                    sum += MOD;
                }
                dq.pop_front();
            } 
            dq.emplace_back(j,dp[i-1][j]);
            sum = (sum + dp[i-1][j]) % MOD;

            dp[i][j] = sum;
        }
    }
    // for (int i=0;i<n;i++) {
    //     pary(dp[i],dp[i]+k+1);
    // }
    cout << dp[n-1][k] << endl;
    return 0;
}


Measured memory_bytes: 81040
#include <bits/stdc++.h>
using namespace std;
 
int N, M;
int A[3];
vector<int> G[51];
bool used[51];
bool dp[101][51][51];  // a step, b start, c goal
 
int main(){
 
  cin>>N>>M;
  for(int i=0;i<3;i++)cin>>A[i];
  for(int i=0;i<M;i++){
    int f,t;
    cin>>f>>t;
    f--;t--;
    G[f].push_back(t);
  }
 
  for(int i=0;i<N;i++)
    dp[0][i][i] = true;
  for(int i=1;i<101;i++){
    for(int j=0;j<N;j++){
      for(int k=0;k<N;k++){
        if(dp[i-1][j][k]){
          for(int to : G[k]){
            dp[i][j][to] = true;
          }
        }
      }
    }
  }
   
  used[N-1] = true;
  for(int ite=1;;ite++){
    bool ok = false;
    vector<int> idx;
    for(int i=0;i<N;i++){
      if(used[i])continue;
      int cnt = 0;
      for(int j=0;j<3;j++){
        int a = A[j];
        bool t = false;
        for(int k=0;k<N;k++){
          if(dp[a][i][k] && used[k]){
            t = true;
          }
        }
        if(t){
          cnt++;
        }
      }
      // OK
      if(cnt == 3){
        ok=true;
        idx.push_back(i);
      }
    }
    if(ok){
      for(int i : idx){
        used[i]=true;
      }
      if(used[0]){
        cout<<ite<<endl;
        return 0;
      }
    }
    else{
      break;
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
   
  return 0;
}

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

template <typename T> inline void read (T &x) {bool b = 0; char c; while (!isdigit (c = getchar()) && c != '-');
if (c == '-') c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x<<3) + (x<<1) + c - 48; if (b)x=-x;}
template <typename T> inline void wrip(T x) {if (x > 9) wrip(x / 10); putchar(x%10 + 48); }

template <typename T> inline void write(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar(' ');}
template <typename T> inline void writeln(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar('\n');}
inline char readch() {char c; do c = getchar(); while (c == '\n' || c == ' '); return c;}
inline void reads(string &s) {char c; while((c=getchar())==' '||c =='\n'); s=c; while((c=getchar())!=' '&&c!='\n') s+=c;}
inline void getlines(string &s) {char c; while((c=getchar())=='\n'); s=c; while((c=getchar())!='\n') s+=c;}
typedef const int csint;

#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;

const ld pi = acos(-1);
const ll inf = 1e9;
const int mod = 1e9 + 7,
N = 2e5 + 11;

int n, m;
int main() {
    #ifdef makacha
        freopen("m.inp", "r", stdin);
        freopen("m.out", "w", stdout);
    #endif // makacha
    cin >> n >> m;
    if (n >= 10)
        cout << m;
    else
        cout << m + 100 * (10 - n);
}


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

using namespace std;

int main()
{
    int a, b; cin >> a >> b;
    if(a < b){
        for(int i = 0;i < b;i++){
            cout << a;
        }
    }else{
        for(int i = 0;i < a;i++){
            cout << b;
        }
    }
}

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

/*
  let's try computer shogi!!!
 */

/*
  最初に全部の種目を開くとする
  この状態よりも参加人数が最大の種目を減らすなら、最も参加人数が多い種目を中止するしか無い
  以下繰り返しで解ける...はず。
 */


// m番目の種目をやめる
void cancelHighest(const int m, vector<bool> &canceled, vector< vector<int> > &order, vector<vector<int> > &pnum, int N, int M){
  canceled[m] = true;
  for(int i=0;i<pnum[m].size();++i){
    for(int j=0;j<M;++j){
      if(!canceled[order[pnum[m][i]][j]]){
	pnum[order[pnum[m][i]][j]].push_back(pnum[m][i]);
	break;
      }
    }
  }
  pnum[m].clear();
}

void pcount(int &maxido, int &maxnumo, vector< vector<int> > &pnum, int N, int M){
  // 最初の時点でのmaxを取得しておく
  int maxnum = 0; //参加人数
  int maxid = 0; //種目ID
  for(int i=0;i<M;++i){
    if(maxnum < pnum[i].size()){
      maxid = i;
      maxnum = pnum[i].size();
    }
  }
  maxido = maxid;
  maxnumo = maxnum;
}

int main(){
  int N;
  int M;
  
  cin >> N >> M;

  vector< vector<int> > order;
  vector<bool> canceled; //種目がcancelされたか
  vector<vector<int> > pnum; // 現状どの種目に誰が参加希望しているか

  order.resize(N);
  canceled.resize(M);
  pnum.resize(M);
  
  for(int i=0;i<N;++i){
    order[i].resize(M);
    for(int j=0;j<M;++j){
      cin >> order[i][j];
      order[i][j] -= 1;
    }
    pnum[order[i][0]].push_back(i);
  }

  int maxid = -1;
  int maxnum = -1;
  pcount(maxid, maxnum,pnum, N, M );
  
  // debug
  //cout <<"max"<< maxid<<","<<maxnum<<endl;
  for(int loop = 0; loop < M-1 ;++loop){
    int after = 0;
    int afterid =0;
    cancelHighest(maxid, canceled, order, pnum, N, M);
    pcount(afterid, after,pnum, N, M);
    //cout <<"max"<< maxid<<","<<maxnum<<endl;
    if(maxnum >= after){
      maxnum = after;
    }
    maxid = afterid;
  }
  cout<<maxnum;
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
typedef long long ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll a,b,c,d;
    a=n/500;
    b=a*500;
    c=(n-b)/5;
    d=(a*1000)+(c*5);
    cout<<d<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {
	int n, m;
	cin >> n >> m;
	priority_queue<int> q;

	rep(i,n){
		int a;
		cin >> a;
		q.push(a);
	}
	rep(i,m){
		int a = q.top();
		q.pop();
		q.push(a / 2);
	}
	ll ans = 0;
	rep(i,n){
		ans += q.top();
		q.pop();
	}
	cout << ans << endl;
}


Measured memory_bytes: 892
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int a,b,c; cin>>a>>b>>c;
    cout<<(b-a==c-b ? "YES" : "NO")<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int N,R;
	int Z;
	scanf("%d %d",&N,&R);
	Z=100*(10-N);
	if(N>=10){
		printf("%d",R);
	}
	else if(N<10){
		printf("%d",R+Z);
	}
	return 0;
}

Measured memory_bytes: 1704
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MAXN 4000007
#define mo 998244353
#define ll long long
using namespace std;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
ll f[4002][4002],g[2002][2002],b[5001],ans[4005],c[2005],n,k;
int main()
{
	cin>>k>>n;
	f[0][0]=1;
	for(re int i=1;i<=k+n;i++){
		f[i][0]=1;
		for(re int j=1;j<=i;j++){
			f[i][j]=(f[i-1][j-1]+f[i-1][j])%mo;
		}
	}
	g[0][k]=1;
	for(re int i=1;i<=k;i++) g[1][i]=i;
	for(re int i=1;i<=n;i++) g[i][1]=1;
	for(re int i=2;i<=n;i++)
		for(re int j=2;j<=k;j++)
			g[i][j]=(g[i-1][j]+g[i][j-1])%mo;
	for(int i=1;i<=k;i++)
		for(re int j=i;j<=k;j++)
			b[i+j]++;
	for(re int i=2;i<=2*k;i++){
		for(re int j=0;j<=b[i]+(i%2==0?1:0)&&(j*2<=n);j++){
			if(!(j&1)) ans[i]=(ans[i]+f[b[i]][j]*g[n-2*j][k]%mo)%mo;
			else ans[i]=(ans[i]-f[b[i]][j]*g[n-2*j][k]%mo+mo)%mo;
		}
	}
	for(re int i=2;i<=2*k;i++) cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 156800
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Split(' ');

        var dict = new Dictionary<int, int>();
        var dx = new[] { -1, 0, 1 };
        for (int i = 0; i < n; i++)
        {
            var x = int.Parse(s[i]);
            for (int j = 0; j < 3; j++)
            {
                var sx = x + dx[j];
                if (dict.ContainsKey(sx))
                {
                    dict[sx]++;
                }
                else
                {
                    dict[sx] = 1;
                }
            }
        }

        var ans = 0;
        foreach (var item in dict)
        {
            ans = Math.Max(ans, item.Value);
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 21600
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  int a,b;cin >> a>> b;
  int tmp = a * b;
  string ans = "Odd";
  if(tmp%2==0){ans = "Even";}
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        char ar[]= new char[n];
        int k=in.nextInt();
        ar=in.next().toCharArray();
        char ch=Character.toLowerCase(ar[k-1]);
        ar[k-1]=ch;
        for(char x:ar)
        {
            System.out.print(x);
        }    
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

signed main()
{
  //ios::sync_with_stdio(false);
  int a[16];
  while (~scanf("%1d", &a[0])){
    REPS(i, 1, 10) scanf("%1d", &a[i]);
    REP(i, 9){
      REP(j, 9 - i){
        a[j] = (a[j] + a[j + 1]) % 10;
        //cout << a[j];
      }
      //print("");
    }
    print(a[0]);
  }

  return (0);
}

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

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

    vector<int> a(n);
    rep(i,n){
        cin >> a.at(i);
    }

    sort(a.begin(),a.end(),greater<int>());

    ll sum=0;
    rep(i,n){
        sum+=a.at(i);
    }

    
    if(a.at(m-1)>=sum/(4*(double)m)){
        cout << "Yes" << endl;
    }else{
        cout << "No" <<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int a,b;
	cin>>a>>b;
	if(a>=13) cout<<b<<endl;
	else if(a>=6)cout<<b/2<<endl;
	else cout<< 0<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
struct node{
	int key;
	node *pre, *next;
};
node *nil;
void init(){
	nil = (node *) malloc(sizeof(node));
	nil->pre = nil;
	nil->next = nil;
}
void insert(int k){
	node *x = (node *)malloc(sizeof(node));
	x->key = k;
	x->next = nil->next;
	nil->next->pre = x;
	nil->next = x;
	x->pre = nil;
}

node* searchList(int k){
	node *p = nil->next;
	while(p != nil && p->key != k){
		p = p->next;
	}
	return p;
}
void deleteNode(node *t){
	if(t == nil) return;
	t->pre->next = t->next;
	t->next->pre = t->pre;
	free(t);
}
void deleteKey(int key){
	deleteNode(searchList(key));
}
void deleteFirst(){
	deleteNode(nil->next);
}
void deleteLast(){
	deleteNode(nil->pre);
}
void printList(){
	node *p = nil->next;
	int sf = 0;
	while(p != nil){
		if(sf++ > 0) printf(" ");
		printf("%d", p->key);
		p = p->next;
	}
	printf("\n");
}
int main() {
	init();
	int n;
	scanf("%d", &n);
	char s[20];
	int key;
	for(int i=0; i<n; i++){
		scanf("%s%d", s, &key);
		if(s[0] == 'd'){
			if(strlen(s) > 6){
				if(s[6] == 'F'){
					deleteFirst();
				}else if(s[6] == 'L'){
					deleteLast();
				}
			}else {
				deleteKey(key);
			}
		}else if(s[0] == 'i'){
			insert(key);
		}
	}
	printList();
	return 0;	
}

Measured memory_bytes: 34384
import math
N, D = map(int, input().split())
p=[]
for _ in range(N):
    p.append(list(map(int, input().split())))

dis=[]
for a in p:
    for b in p:
        n = 0
        for i in range(D):
            n = n + (a[i]-b[i])**2
        if not n==0:
            dis.append(n)
print(len([d for d in dis if int(math.sqrt(d))**2==d])//2)

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

int N, arr[100], ans=0;

int main () {
	cin >> N;
	for(int i=1; i<=N; i++)
		cin >> arr[i];
	for(int i=1; i<=N; i++)
		for(int j=i+1; j<=N; j++)
			ans += arr[i]*arr[j];
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,L,T;
    cin>>N>>L>>T;
    int x[N],w[N];
    for(int i=0;i<N;i++)cin>>x[i]>>w[i];
    int count=0;
    int y[N];
    
    for(int i=0;i<N;i++){
        if(w[i]==1) {
          y[i]=(x[i]+T)%L;
        count+=(x[i]+T)/L;

        }
        else {
            y[i]=(x[i]-T)%L;
            count+=(x[i]-T)/L;
            if(y[i]<0){
                y[i]+=L;
                count--;
            }
            
        }
    }
        sort(y,y+N);
        count=(count%N+N)%N;
        for(int i=count;i<N;i++){
            cout<<y[i]<<endl;
            }
        for(int i=0;i<count;i++){
            cout<<y[i]<<endl;
        }
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define P pair<int,int>
#define Pil pair<int,ll>
#define Pli pair<ll,int>
#define Pll pair<ll,ll>
#define pb push_back 
#define pc putchar
#define mp make_pair
#define file(k) memset(k,0,sizeof(k))
#define ll long long
int rd()
{
	int num = 0;char c = getchar();bool flag = true;
	while(c < '0'||c > '9') {if(c == '-') flag = false;c = getchar();}
	while(c >= '0' && c <= '9') num = num*10+c-48,c = getchar();
	if(flag) return num;else return -num;
}
int a[101000];
int main()
{
	int n = rd(),k = rd();
	rep(i,1,n) a[i] = rd();
	sort(a+1,a+n+1);
	int ans = 2e9;
	for(int i = 1;i <= n-k+1;++i)
	    ans = min(ans,a[i+k-1]-a[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include <climits>
#include<queue>
#include<functional>
#include<vector>
#include<map>
#include<stack>
using namespace std;

#define INF 1<<30









int main()
{
   char ch[12];
   scanf("%s",ch);
   if(ch[0]!='A'){cout<<"WA";return 0;}
   int len=strlen(ch);
   int first=2;
   int last=len-2;int c=0;
   if(first>last){swap(first,last);}
   for(int i=first;i<=last;i++)
   {

       if(ch[i]=='C'){c++;ch[i]='c';}
   }
   if(c!=1){cout<<"WA";return 0;}
   for(int i=1;i<len;i++)
   {
       if(ch[i]<'a'||ch[i]>'z'){cout<<"WA";return 0;}
   }
   cout<<"AC";



	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

const int MAX_W = 9;
const int MAX_H = 101;

int dp[MAX_H][MAX_W]; // dp[h][w] : 高さhまで見たとき，wに行く通り数

void addMOD(int& a, int b) {
    a = (a + b)%MOD;
}

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    dp[0][0] = 1; //初期条件
    rep(h, H) {
        for(int bit = 0; bit < (1 << (W - 1)); ++bit) {
            bool flg = true;
            rep(w, W - 2) {
                if(((1 << w) & bit) && ((1 << (w + 1)) & bit))
                    flg = false;
            }
            if(!flg)continue;
            rep(w, W) {
                if(((1 << (w - 1)) & bit) && w != 0) {
                    addMOD(dp[h + 1][w - 1], dp[h][w]);
                }else if(((1 << w) & bit) && w != W - 1) {
                    addMOD(dp[h + 1][w + 1], dp[h][w]);
                }else {
                    addMOD(dp[h + 1][w], dp[h][w]);
                }
            }
        }
    }
    cout << dp[H][K - 1] << endl;
}


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

int N,A,B;

int isRange(int u){
  int dig,sum=0;
  while(u){
    dig=u%10;
    sum+=dig;
    u=u/10;
  }
  if(sum>=A&&sum<=B)return 1;
  else return 0;
}

int main(){
  cin>>N>>A>>B;
  int sum=0;

  for(int i=1;i<=N;i++){
    if(isRange(i)==1) sum+=i;
  }

  cout<<sum;

  return 0;
}


Measured memory_bytes: 256
n, x0 = map(int, input().split())

x = list(map(int, input().split()))
minx = min(min(x), x0)

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

gcdx = x0 - minx
for xx in x:
    gcdx = gcd(gcdx, xx-minx)

print(gcdx)



Measured memory_bytes: 15020
import sys

readline = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def main():
    N, Q = map(int, readline().split())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, readline().split())
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)
    X = [0] * N
    for i in range(Q):
        p, x = map(int, readline().split())
        X[p - 1] += x

    C = [0] * N

    def dfs(v, p, count):
        C[v] = count + X[v]
        for nv in G[v]:
            if nv != p:
                dfs(nv, v, C[v])

    dfs(0, -1, 0)

    print(*C)
    return


if __name__ == '__main__':
    main()


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

import sys
sys.setrecursionlimit(300000)


def solve(N: int, u: int, v: int, A: "List[int]", B: "List[int]"):
    u -= 1
    v -= 1
    conns = [[] for _ in range(N)]
    for j in range(N - 1):
        conns[A[j] - 1].append(B[j] - 1)
        conns[B[j] - 1].append(A[j] - 1)

    def dfs(idx, cur, dis):
        dis[idx] = cur
        for conn in conns[idx]:
            if dis[conn] < 0:
                dis = dfs(conn, cur + 1, dis)
        return dis

    dis_u = [-1] * N
    dis_u = dfs(u, 0, dis_u)
    dis_v = [-1] * N
    dis_v = dfs(v, 0, dis_v)
    ret = 0
    for i in range(N):
        if dis_u[i] < dis_v[i]:
            ret = max(ret, dis_u[i] + (dis_v[i] - dis_u[i] - 1))
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = int(next(tokens))  # type: int
    v = int(next(tokens))  # type: int
    A = [int()] * (N - 1)  # type: "List[int]"
    B = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, u, v, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 124808
while(True):
    A,op,B = map(str,input().split())
    if op == "?":
        break
        exit()
    if op == "+":
        print(int(A)+int(B))
    elif op == "-":
        print(int(A)-int(B))
    elif op == "*":
        print(int(A)*int(B))
    elif op == "/":
        print(int(A)//int(B))
    else:
        break




Measured memory_bytes: 5596
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <stack>
#include <unordered_map>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 200005;
int n, m;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;

ll asc[MAXN];
ll k;
bool check(ll x) {
    ll cnt = 0;
    for (int i = 1; i <= n; i++) {
        if (asc[i] < 0) {
            int p = 0;
            if (x >= 0)
                p = lower_bound(asc + i + 1, asc + n + 1, x / asc[i]) - asc;
            else
                p = lower_bound(asc + i + 1, asc + n + 1,
                                (x + asc[i] + 1) / asc[i]) -
                    asc;
            cnt += n - p + 1;
        } else if (asc[i] == 0 && x >= 0) {
            cnt += n - i;
        } else if (asc[i] > 0) {
            auto p = upper_bound(asc + i, asc + n + 1, x / asc[i]) - asc;
            if (p > i) p--;
            cnt += p - i;
        }
    }
    return cnt >= k;
}
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    n = read<int>(), k = read<ll>();
    for (int i = 1; i <= n; i++) {
        asc[i] = read<ll>();
    }
    sort(asc + 1, asc + n + 1);

    ll l = (ll)-2e18, r = (ll)2e18;
    ll ans = r;
    while (l <= r) {
        ll mid = l + (r - l) / 2LL;
        if (check(mid)) {
            ans = mid, r = mid - 1LL;
        } else {
            l = mid + 1LL;
        }
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 1792
N,M = map(int,input().split())
if N==1 and M==1:
    print(1)
elif (N>=1 and M==2) or (N==2 and M>=1):
    print(0)
elif (N==1 and M>=3) or (N>=3 and M==1):
    print(max(N,M)-2)
elif N>=3 and M>=3:
    print((N-2)*(M-2))

Measured memory_bytes: 61532
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    std::cout << std::fixed << std::setprecision(3);
    float R;
    cin >> R;

    float ans = 2 * R * PI;
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 3780
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let v: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    if v[0] + v[1] == v[2] || v[1] + v[2] == v[0] || v[0] + v[2] == v[1] {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(int i = a; i < b; i++)
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a <= c && a+b >= c) cout << "YES\n";
  else cout << "NO\n";
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long 
#define inf 1000000007
using namespace std;
long long int maxProductSubarrayOfSizeK(long long int A[],long long  int n,long long  int k) 
{ 
    // sorting given input array 
    sort(A, A + n); 
  
    // variable to store final product of all element 
    // of sub-sequence of size k 
    long long int product = 1; 
  
    // CASE I 
    // If max element is 0 and 
    // k is odd then max product will be 0 
    if (A[n - 1] == 0 && (k & 1)) 
        return 0; 
  
    // CASE II 
    // If all elements are negative and 
    // k is odd then max product will be 
    // product of rightmost-subarray of size k 
    if (A[n - 1] <= 0 && (k & 1)) { 
        for (ll int i = n - 1; i >= n - k; i--) 
            product = ((product)*(A[i]%inf))%inf; 
        return product; 
    } 
  
    // else 
    // i is current left pointer index 
    ll int i = 0; 
  
    // j is current right pointer index 
    ll int j = n - 1; 
  
    // CASE III 
    // if k is odd and rightmost element in 
    // sorted array is positive then it 
    // must come in subsequence 
    // Multiplying A[j] with product and 
    // correspondingly changing j 
    if (k & 1) { 
        product = ((product)*(A[j]%inf))%inf; 
        j--; 
        k--; 
    } 
  
    // CASE IV 
    // Now k is even 
    // Now we deal with pairs 
    // Each time a pair is multiplied to product 
    // ie.. two elements are added to subsequence each time 
    // Effectively k becomes half 
    // Hence, k >>= 1 means k /= 2 
    k >>= 1; 
  
    // Now finding k corresponding pairs 
    // to get maximum possible value of product 
    for (ll int itr = 0; itr < k; itr++) { 
  
        ll int left_product = ((A[i])* (A[i + 1])); 
  
        ll int right_product = ((A[j]) * (A[j - 1])); 
  
        if (left_product > right_product) { 
            product = ((product)*(left_product%inf))%inf; 
            i += 2; 
        } 
        else { 
            product = ((product)*(right_product%inf))%inf; 
            j -= 2; 
        } 
    } 
    return (product)%inf; 
} 
int main(){
	long long int k=0,n,z=0,i=0,sum=0;
  cin >> n>>k;
  long long int arr[n];
  for(i=0;i<n;i++){
  	cin >> arr[i];
  }
  ll int prod = maxProductSubarrayOfSizeK(arr,n,k);
  if(prod<0){prod = prod+inf;}
  cout << prod<<endl;
}

Measured memory_bytes: 5132