akhauriyash/Code-Regression huggingface dataset:
-module('Main').
-export([main/1]).

-define(MOD, 1000000007).

pow(A, E) -> pow(A, E, 1).
pow(_A, 0, Acc) -> Acc;
pow(A, E, Acc) when E rem 2 =:= 1 -> pow(A * A rem ?MOD, E div 2, Acc * A rem ?MOD);
pow(A, E, Acc) -> pow(A * A rem ?MOD, E div 2, Acc rem ?MOD).

solve() ->
    [N, K] = input("~d~d"),
    Arr0 = maps:from_list([{I, pow(K div I, N)} || I <- lists:seq(1, K)]),
    Arr1 = lists:foldl(fun (I, Acc) ->
        lists:foldl(fun (J, Acc) ->
            Value = (maps:get(I, Acc) - maps:get(I * J, Acc) + ?MOD) rem ?MOD,
            Acc#{I => Value}
        end, Acc, lists:seq(2, K div I))
    end, Arr0, lists:reverse(lists:seq(1, K))),
    Sum = maps:fold(fun (I, Val, Acc) ->
        (Acc + I * Val) rem ?MOD
    end, 0, Arr1),
    io:format("~B~n", [Sum]),
    ok.

main(_) ->
    solve(),
    halt().

input(Pat) ->
    {ok, L} = io:fread("", Pat),
    L.


Measured memory_bytes: 78728
#include <bits/stdc++.h>
#define REP(i, a) for(int i = 0; i < (a); i++)
using namespace std;
signed main()
{
    int a, b, c; cin >> a >> b >> c;
    int ans = 0;
    for(int i = a; i <= b; i++) if(c % i == 0) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 3092
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll h,w ;
	cin >> h >> w ;
	vvc g(h+2,vc(w+2,'#')) ;
	for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) cin >> g.at(i).at(j) ;
	vvll yoko(h+2,vll(w+2,-1)) ;
	for(int i=1;i<=h;i++){
		ll pos = 0 ;
		ll cnt = 0 ;
		for(int j=1;j<=w+1;j++){
			if(g.at(i).at(j)=='#'){
				for(int k=pos;k>=0;k--){
					if(yoko.at(i).at(k)!=-1||g.at(i).at(k)=='#') break ;
					yoko.at(i).at(k) = cnt ;
				}
				cnt = 0 ;
			}else{
				pos = j ;
				cnt++ ;
			}
		}
	}
	vvll tate(h+2,vll(w+2,-1)) ;
	for(int j=1;j<=w;j++){
		ll cnt = 0 ;
		for(int i=1;i<=h+1;i++){
			if(g.at(i).at(j)=='#'){
				for(int k=0;k<cnt;k++){
					tate.at(i-1-k).at(j) = cnt ;
				}
				cnt = 0 ;
			}else{
				cnt++ ;
			}
		}
	}
	ll ans = 0 ;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(g.at(i).at(j)=='#') continue ;
			ans = max(ans,yoko.at(i).at(j)+tate.at(i).at(j)) ;
		}
	}
	cout << ans-1 << endl ;
}


Measured memory_bytes: 67072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <numeric>
#define rep(i,s,n) for (int i = s; i < n; ++i)
#define drep(i,s,n) for (int i = n; i >= s; --i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

int gcd(int a, int b)
{
   if (a%b == 0) return(b);
   else          return(gcd(b, a%b));
}
int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
void printvv(vector<vector<auto>> vv, int n)
{
  cout << '[' << endl;
  rep(q, 0, n)
  {
    cout << '[';
    rep(p, 0, n)
    {
      cout << vv.at(q).at(p) << ',';
    }
    cout << ']' << endl;
  }
  cout << ']' << endl;
}

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

//------------------------------------------------------------
void solve() {
  int a,b,c,d,e=7,tmp1=0,tmp2=0,tmp3=0;
  string s;
  char op1,op2,op3;
  cin>>s;

  a=(int)(s[0]-'0');b=(int)(s[1]-'0');c=(int)(s[2]-'0');d=(int)(s[3]-'0');

  e-=a;

  rep(i,0,2)
  {
    tmp1=e;
    if(i==0) {e-=b;op1='+';}
    else     {e+=b;op1='-';}
    rep(j,0,2)
    {
      tmp2=e;
      if(j==0) {e-=c;op2='+';}
      else     {e+=c;op2='-';}
      rep(k,0,2)
      {
        tmp3=e;
        if(k==0) {e-=d;op3='+';}
        else     {e+=d;op3='-';}
        if (e==0)
        {
          cout<<a<<op1<<b<<op2<<c<<op3<<d<<"=7"<<endl;
          return;
        }
        e=tmp3;
      }
      e=tmp2;
    }
    e=tmp1;
  }

  return;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int ll
using namespace std;
const int N = 2e5+5;
const int mod=1e9+7;
int n,m,x[N],tot;bool f[N],spec;
pii p[N];vi a,b;int X,Y;ll res1=-1,res2=-1,ans=1;
signed main()
{
	Very_fast;
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>p[i].F;
	for(int i=0;i<n;i++)if(p[i].F<0)p[i].S=1,p[i].F=-p[i].F;
	sort(p,p+n);reverse(p,p+n);
	for(int i=0;i<n;i++)
	{
		x[i]=p[i].F;
		f[i]=p[i].S;
		tot+=f[i];
		if(f[i])a.pb(x[i]);
		else b.pb(x[i]);
	}
	int sum=0;
	for(int i=0;i<m;i++)sum+=f[i],X+=f[i],Y+=!f[i];
	if((m%2==1&&tot==n)){ll ans=1;for(int i=n-1;i>=n-m;i--)ans=ans*x[i]*(f[i]?-1ll:1ll)%mod;ans=(ans+mod)%mod;cout<<ans<<"\n";return 0;}
	if(n==m||sum%2==0){ll ans=1;for(int i=0;i<m;i++)ans=ans*x[i]*(f[i]?-1ll:1ll)%mod;ans=(ans+mod)%mod;cout<<ans<<"\n";return 0;}
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++m%2=1,sum%2=1,X>0
	ll pre=1;
	if(Y==0){ans=b[0];for(int i=0;i<m-1;i++)ans=ans*a[i]%mod;cout<<ans<<"\n";return 0;}//前方都负
	if(sum==tot){for(int i=0;i<Y+1;i++)ans=ans*b[i]%mod;for(int i=0;i<X-1;i++)ans=ans*a[i]%mod;cout<<ans;return 0;}//后方都正 
	if(tot-sum==n-m){for(int i=0;i<X+1;i++)ans=ans*a[i]%mod;for(int i=0;i<Y-1;i++)ans=ans*b[i]%mod;cout<<ans;return 0;}//后方都负
	for(int i=0;i<X-1;i++)pre=pre*a[i]%mod;for(int i=0;i<Y-1;i++)pre=pre*b[i]%mod;
	res1=a[X]*a[X-1];
	res2=b[Y]*b[Y-1];
	if(res1<res2)swap(res1,res2);
	cout<<res1%mod*pre%mod<<"\n";
	return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int gcd(int a, int b) {
  if (a < b) swap(a, b);

  int r;
  while (b > 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) {
    int c; cin >> c;
    v.at(i) = abs(x - c);
  }
  sort(v.begin(), v.end());
  int res = v.at(n - 1);
  if (n == 1) {
    res = v.at(0);
  } else {
    for (int i = 0; i < n; ++i) {
      res = gcd(res, v.at(i));
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 640
import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
C = [int(a) - 1 for a in input().split()]
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

def EulerTour(n, X, i0):
    f = lambda k: k * (k + 1) // 2
    USED = [0] * n
    ORG = [0] * n
    TMP = [0] * n
    P = [-1] * n
    Q = [~i0, i0]
    ct = -1
    ET1 = [0] * n
    ET2 = [0] * n
    ANS = [f(n)] * n
    while Q:
        i = Q.pop()
        if i < 0:
            i = ~i
            ET2[i] = ct
            USED[C[i]] += 1 + TMP[i]
            if i:
                p = P[i]
                k = ET2[i] - ET1[i] + 1 - USED[C[p]] + ORG[i]
                ANS[C[p]] -= f(k)
                TMP[p] += k
            continue
        if i >= 0:
            if i: ORG[i] = USED[C[P[i]]]
            ct += 1
            if ET1[i] == 0: ET1[i] = ct
        for a in X[i][::-1]:
            if a != P[i]:
                P[a] = i
                for k in range(len(X[a])):
                    if X[a][k] == i:
                        del X[a][k]
                        break
                Q.append(~a)
                Q.append(a)
    for i in range(n):
        ANS[i] -= f(n - USED[i])
    return ANS

print(*EulerTour(N, X, 0), sep = "\n")

Measured memory_bytes: 76532
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
using Graph=vector<vector<int>>;
Graph G;
ll dp[100010];
//vを始点とした最長長さ
int rec(int v){
    if(dp[v]!=-1) return dp[v];
    int res=0;
    for(auto nv : G[v]){
        res=max(res,rec(nv)+1);
    }
    return dp[v]=res;
}

signed main(){
    int n,m;
    cin >> n >> m;
    G.assign(n,vector<int>());
    //to.assign(n,vector<int>());
    
    for (int i = 0; i < m; i++)
    {
        int x,y;
        cin>>x>>y;
        x--,y--;
        G[x].push_back(y);
      //  to[y].push_back(x);
    }
    fill(dp,dp+100010,-1);
    int res=0;
    for (int i = 0; i < n; i++)
    {
        chmax(res,rec(i));
    }
    cout<< res << endl;

    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
ll a[200010];
ll test[200010];
ll test2[200100];

void query(int from, int to) {
    if(from >= to) return;
    //cerr << "query " << from << " " << to << endl;
    int before = from;
    while((test[before] != 1) || (test[before+1] != 1)) {
        before++;
        if(before == to) return;
    }
    int after = to;
    while((test[after] != 1) || (test[after-1] != 1)) after--;
    //cerr << from << " " << before << " " << after << " "<< to << endl;
    for(int i = before; i <= after; i++) test2[i] = 1;
    for(int i = 1; i <= (before - from) / 2; i++) {
        test2[before - i] = 1;
    }
    for(int i = 1; i <= (to - after) / 2; i++) {
        test2[after + i] = 1;
    }
}

int connected(int from) {
    //cerr << "connected " << from << endl;
    int to = from;
    while(true) {
        if(test[to+1] == 0 && test[to] == 0) break;
        to++;
    }
    query(from, to - 1);
    return to;
}

void search(int from) {
    if(from > 2*N-1) return;
    if(test[from] == 0) {
        search(from+1);
        return;
    }
    search(connected(from) + 1);
}

int main() {
    //cout.precision(10);
    cin >> N;
    for(int i = 1; i <= 2 * N - 1; i++) cin >> a[i];
    ll ok = 2 * N - 1;
    ll ng = 1;
    while(ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        //cerr << "MID " << mid << endl;
        for(int i = 1; i <= 2*N-1; i++) {
            test2[i] = 0;
            if(a[i] <= mid) test[i] = 1;
            else test[i] = 0;
        }
        bool checker = true;
        for(int i = 1; i <= 2*N-1; i+=2) {
            if(test[i] == 0) checker = false;
        }
        if(checker) {
            ok = mid;
            continue;
        }
        search(1);
        /*
        for(int i = 1; i <= 2*N-1; i++) {
            cout << test[i] << " ";
        }
        cout << endl;
        for(int i = 1; i <= 2*N-1; i++) {
            cout << test2[i] << " ";
        }
        cout << endl;
        */
        if(test2[N] == 1) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}


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

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
    cin >> a[i][j];
    }
  }
  int n; cin >> n;
  for(int i=0;i<n;i++){
    int b;cin >> b;
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
       if(a[i][j]==b)a[i][j]=0;
      }
    }
  }
  bool ans=0;
  for(int i=0;i<3;i++){ //横一列0
    if(a[i][0]==0 && a[i][1]==0 && a[i][2]==0)ans=1;
  }
  for(int i=0;i<3;i++){ //縦一列0
    if(a[0][i]==0 && a[1][i]==0 && a[2][i]==0)ans=1;
  }

  if((a[0][0]==0 && a[1][1]==0 && a[2][2]==0 ) || (a[2][0])==0 && a[1][1]==0 && a[0][2]==0)ans=1;

  if(ans)cout << "Yes" << endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int h = sc.nextInt(); int w = sc.nextInt();
			if (h == 0 && w == 0) { break; }
			for (int i = 0; i < h; i++) {
				if (i == 0 || i == h - 1) {
					for (int j = 0; j < w; j++) {
						System.out.print("#");
					}
				} else {
					for (int j = 0; j < w; j++) {
						if (j == 0 || j == w - 1) {
							System.out.print("#");
						} else {
							System.out.print(".");
						}
					}
				}
				System.out.print("\n");
			}
			System.out.print("\n");
		}
	}
}


Measured memory_bytes: 36240
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 10000000000000001
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long> 
#define pb push_back
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 100005
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n,w,i,j;
    cin>>n>>w;
    ll val[n],wt[n];
    for(ll i=0;i<n;i++)
    cin>>wt[i]>>val[i];
    ll dp[n+1][w+1];
    rep(i,0,n+1)
    dp[i][0]=0;
    rep(i,0,w+1)
    dp[0][i]=0;
    rep(i,1,n+1)
    {
        rep(j,1,w+1)
        {
            if(j-wt[i-1]>=0)
            {
                dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
               // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;;
            }
            else
            {
                dp[i][j]=dp[i-1][j];
                //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;;
            }
        }
    }
    cout<<dp[n][w];
}

Measured memory_bytes: 79232
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	static int n;
	static int[][]M;	// 隣接行列
	static int[]d;
	static final int INF = 10000000;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		M = new int[n][n];
		d = new int[n];
		for(int i = 0; i < n; i++) {
			int u = scan.nextInt() - 1;
			int k = scan.nextInt();
			for(int j = 0; j < k; j++) {
				M[u][scan.nextInt() - 1] = 1;
			}
		}
		scan.close();
		bfs(0);
	}
	static void bfs(int s) {
		Queue<Integer> queue = new ArrayDeque<Integer>();
		queue.add(s);
		Arrays.fill(d, INF);
		d[s] = 0;
		while(!queue.isEmpty()) {
			int u = queue.poll();
			for(int v = 0; v < n; v++) {
				if(M[u][v] == 0) continue;
				if(d[v] != INF) continue;
				d[v] = d[u] + 1;
				queue.add(v);
			}
		}
		for(int i = 0; i < n; i++) {
			int u = i + 1;
			int l;
			if(d[i] == INF) l = -1;
			else l = d[i];
			System.out.println(u + " " + l);
		}
	}
}


Measured memory_bytes: 28480
K,T = map(int,input().split())
A = sorted(list(map(int,input().split())),reverse=True)

if T == 1:
    print(A[0]-1)
    exit()
su = sum(A[1:])
if A[0] - su >= 2:
    print(A[0] - su - 1)
else:
    print(0)

Measured memory_bytes: 9188
# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase

def main():
    n,x,m = map(int,input().split())
    val,se = [x],{x}
    y = pow(x,2,m)
    while len(val) != n and y not in se:
        val.append(y)
        se.add(y)
        y = pow(y,2,m)
    if len(val) == n:
        print(sum(val))
    else:
        ans = sum(val)
        n -= len(val)
        ind = 0
        for i in range(len(val)):
            if val[i] == y:
                ind = i
                break
        val = val[ind:]
        xxx = sum(val)
        ans += xxx*(n//len(val))
        ans += sum(val[:n%len(val)])
        print(ans)
    
#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()

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

// A and T, G and C
char counterpart(char c) {
    if (c == 'A') return 'T';
    if (c == 'T') return 'A';
    if (c == 'G') return 'C';
    return 'G';
}


int main() {
    char c; cin >> c;
    cout << counterpart(c) << endl;
    return 0;
}


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

string s = "ACGT";
string t = "TGCA";

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

  char c; cin >> c;
  for(int i = 0; i < s.size(); i++){
    if(c == s[i]){
      cout << t[i] << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}
const int nax=3005;
ll dp[nax][nax];

void solve() {
    int n;cin>>n;
    vector<int> v(n);fr(i,0,n-1)cin>>v[i];
    frr(l,n-1,0){
        fr(r,l,n-1){
            if(l==r)dp[l][r]=v[l];
            else{
                dp[l][r]=max(v[l]-dp[l+1][r],v[r]-dp[l][r-1]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    return ;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}


Measured memory_bytes: 49776
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N, M;
    cin >> N >> M;
    map<long, long> A;
    for(size_t i=0;i<N; i++)
    {
        long K;
        cin >> K;
        for(size_t k=0;k<K; k++)
        {
            long a;
            cin >> a;
            A[a]++;
        }
    }
    long count = 0;
    for(const auto& a:A)
    {
        if(a.second == N) count++;
    }
    cout << count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
edge = []
hand_a = [100005]*(n+1)
hand_b = [100005]*(n+1)
for i in range(n+1):
    edge.append([])
for i in range(n-1):
    a,b = map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)

# print(edge)
def dfs(start, goal, hand):
    cnt = 0
    hand[start] = 0
    stack = [start]
    used = set()
    used.add(start)
    while stack:
        here = stack.pop()
        cnt += 1
        for i in edge[here]:
            if i == goal:
                pass
            elif i not in used:
                stack.append(i)
                used.add(i)
                hand[i] = hand[here] + 1
    return cnt, used


cnt_a, used_a = dfs(1, n, hand_a)
cnt_b, used_b = dfs(n, 1, hand_b)
# print(cnt_a, cnt_b)
# print(used_a, used_b)
# print(hand_a, hand_b)
a_ans = b_ans = 0
for i in range(1,n+1):
    if hand_a[i] <= hand_b[i]:
        a_ans += 1
    else:
        b_ans += 1
if a_ans > b_ans:
    print("Fennec")
else:
    print("Snuke")



# work_q = deque([1])
# used = set()
# used.add(1)
# ans[1] = cost[1]
# cnt = 0
# while work_q:
#     here = work_q.popleft()
#     cnt = ans[here]
#     for i in edge[here]:
#         if i not in used:
#             work_q.append(i)
#             used.add(i)
#             ans[i] = cnt + cost[i]
# print(*ans[1:])








Measured memory_bytes: 70812
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define Little 1
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0,w=1,n=11,m=0,o=0;
  std::cin >> x;
  if(x%1000==0)std::cout << 0 << '\n';
  else std::cout << 1000-x%1000 << '\n';
}


Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<PP> Vpp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

bool cp[20001];

int main(){
	int n,m;
	while(scanf("%d%d", &n, &m), n||m){
		rep(i,20001) cp[i] = false;
		cp[1] = true;
		Vpp vec;
		rep(i,m){
			int a,b,c;
			scanf("%d%d%d", &a, &b, &c);
			vec.pb(PP(a,P(b,c)));
		}
		SORT(vec);
		rep(i,m){
			if(!cp[vec[i].sec.fi]) continue;
			cp[vec[i].sec.sec] = true;
		}
		int ans = 0;
		rep(i,20001) if(cp[i]) ans++;
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1676
n = [int(i) for i in input().split(" ")]
l = []
r = []
for j in range(n[1]):
    k = input().split(" ")
    l.append(int(k[0]))
    r.append(int(k[1]))

if min(r) >= max(l):
    print(min(r) - max(l) + 1)
else:
    print(0)


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

int main(){
    int n, c=0; cin>>n;
    string v;
    int ar[4];
    for (int i=0; i<4; i++){
        ar[i]=0;
    }
    for (int i=0; i<n; i++){
        cin>>v;
        if (v=="AC")
            ar[0]++;
        if (v=="WA")
            ar[1]++;
        if (v=="TLE")
            ar[2]++;
        if (v=="RE")
            ar[3]++;
    }
    cout<<"AC x "<<ar[0]<<endl<<"WA x "<<ar[1]<<endl<<"TLE x "<<ar[2]<<endl<<"RE x "<<ar[3];


}


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

int main()
{
  string s;
  cin>>s;
  
  int cs = 0;
  int cnt =0;
  for (int i =0;i<s.length();i++)
  {
    if (s[i]=='S')
      cs++;
    else if (s[i]=='T'&&cs>0)
    {
      cs--;
      cnt++;
    }
  }
  cout << s.length()- cnt*2 << endl;
}
    


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

int main(){
    int K, S;
    cin >> K >> S;
    int ans = 0;
    
    for(int x = 0; x <= K; x++){
        for(int y = 0; y <= K; y++){
            int z = S - x - y;
            if(0 <= z && z <= K)ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    while (true){
        string a="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        int n;
        cin >> n;
        if (n==0) break;
        vector<int> k(n);
        for (int i=0;i<n;i++){
            cin >> k.at(i);
        }
        string s,b="";
        cin >> s;
        int u=0,p=0;
        for (int i=0;i<s.size();i++){
            for (int I=0;I<52;I++){
                if (s.at(i)==a.at(I)) p=I-k.at(u%n);
            }
            if (p<0) p=p+52;
            b.push_back(a.at(p));
            u++;
        }
        cout << b << endl;
    }
}


Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
#define df 0


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

  int d[100000],i,sum=0;;
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
    sum+=d[i];
  }
  sum/=2;
  for(i=1;i<n;i+=2){
    sum-=d[i];
  }
  printf("%d ",2*sum);
  for(i=1;i<n;i++){
    sum=d[i-1]-sum;
    printf("%d ",2*sum);
  }
  return 0;
}


/// confirm df==0 ///


Measured memory_bytes: 1664
fun main() {
    println(solve().toYesOrNo())
}

val solve: () -> Boolean = {
    val S = readString()
    val T = readString()
    S.withIndex().all { (i, c) -> T[i] == c}
}

val mod: Int = 1_000_000_007


fun readString() = readLine()!!
fun readStringList() = readLine()!!.split(" ")
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun <T> T.alsoPrintln() = also { println(this) }

fun Boolean.toYesOrNo(yes: String = "Yes", no: String = "No") = if (this) yes else no

fun <E> List<E>.toPair() = this[0] to this[1]

fun <T> readPair(t: (String) -> T) = readPair(t, t)
fun <S, T> readPair(s: (String) -> S, t: (String) -> T) =
    readLine()!!.split(" ").let { Pair(s(it[0]), t(it[1])) }

fun Int.pow(n: Int) = Math.pow(this.toDouble(), n.toDouble())
fun Int.powInt(n: Int) = pow(n).toInt()

fun minAndMax(a: Int, b: Int) = if (a < b) a to b else b to a


Measured memory_bytes: 35836
use std::io::*;
use std::str::FromStr;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn abc(h: usize, w: usize, mut a: Vec<Vec<i32>>) -> Vec<(usize, usize, usize, usize)> {
    let mut ans = vec![];
    for y in 0..h {
        for x in 0..w {
            if a[y][x] %2 == 1 {
                if x+1 < w {
                    a[y][x] -= 1;
                    a[y][x+1] += 1;
                    ans.push((y, x, y, x+1));
                } else if y+1 < h {
                    a[y][x] -= 1;
                    a[y+1][x] += 1;
                    ans.push((y, x, y+1, x));
                }
            }
        }
    }
    return ans
}

fn main() {
    /*
    assert_eq!(abc(), "Yes");
    assert_eq!(abc(101), "No");
    assert_eq!(abc(999999999), "Yes");
    */
    input!{
        h: usize,
        w: usize,
        a: [[i32; w]; h],
    }
    //let mut a = a;
    let result = abc(h, w, a);

    println!("{}", result.len());
    for (y1, x1, y2, x2) in result {
        println!{"{} {} {} {}", y1+1, x1+1, y2+1, x2+1}
    }
}



Measured memory_bytes: 10996
#include <iostream>

int main()
{
        int best[] = {0, 0, 0};
        int t = 0;
        for(int i = 0; i < 10; ++i)
        {
                std::cin >> t;
                for(int j = 0; j < 3; ++j)
                        if(t > best[j])
                        {
                                for(int k = 2; k > j; --k)
                                        best[k] = best[k - 1];
                                best[j] = t;
                                break;
                        }
        }
        for(int i = 0; i < 3; ++i)
                std::cout << best[i] << std::endl;
        return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
ll i;



int main(){
   string A,B,C;
   cin>>A>>B>>C;
   if(A.at(A.length()-1)==B.at(0)&&B.at(B.length()-1)==C.at(0))cout<<"YES";
   else cout<<"NO";
   cout<<endl;
}


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

A += A

g_rui = [0, A[0]]
k_rui = [0, A[1]]

for i in range(2, 2*N):
    if i % 2 == 0:
        x = g_rui[-1] + A[i]
        g_rui.append(x)
    if i % 2 != 0:
        x = k_rui[-1] + A[i]
        k_rui.append(x)

# print(A)
# print(g_rui)
# print(k_rui)

for i in range(N):
    if i % 2 == 0:
        ind = i//2
        a = g_rui[ind + N//2 + 1] - g_rui[ind]
        b = k_rui[ind + N//2] - k_rui[ind]
        print(a-b)
    else:
        ind = i//2
        a = k_rui[ind + N//2 + 1] - k_rui[ind]
        # print('a', a)
        b = g_rui[ind + N//2 + 1] - g_rui[ind + 1]
        # print('b', b)
        print(a-b)    



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


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

  ll a,b;
  cin >> a >> b;
  cout << a*b << endl;
  
  return 0;
    

}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  ll n,d;
  ll x[200010],y[200010];
  cin>>n>>d;
  rep(i,n)cin>>x[i]>>y[i];
  ll ans=0;
  rep(i,n){
    if(sqrt(x[i]*x[i]+y[i]*y[i])<=d)ans++;
  }


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


Measured memory_bytes: 6800
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n,l;
	while(cin>>n>>l)
	{
		string str[105];
		for(int i=0;i<n;i++)
		  cin>>str[i];

		sort(str,str+n);

		for(int j=0;j<n;j++)
		 cout<<str[j];

		 cout<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define floop(i,a,n) for (int i=a;i<n;i++)
#define rfloop(i,a,n) for (int i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2; 
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;	
				if(spf[j]==j)
				spf[j]=i;	
			}		
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
struct my_comp
{
	bool operator()(pair<ll,pll> p1, pair<ll,pll> p2)
	{
		if(p1.fi!=p2.fi)
		return p1.fi>p2.fi;
		return p1.se.fi<p2.se.fi;
	}
};
int main()
{
	ll n;
	cin>>n;
	vec a(n);
	floop(i,0,n)
	cin>>a[i];
	sort(all(a), greater<ll>());
	ll sum=0;
	if(n%2==0)
	{
		sum+=a[0];
		floop(i,1,n/2)
		sum+=a[i]*2;
		//sum+=a[n/2];
	}
	else
	{
		sum+=a[0];
		floop(i,1,n/2)
		sum+=a[i]*2;
		sum+=a[n/2];
	}
	cout<<sum<<"\n";
	return 0;
}

Measured memory_bytes: 4840
#include <stdio.h>

int main(void){
    
    char s[5];
    scanf("%s",s);
    
    int i, d, k=0;
    
    d = s[0]-48;

    for(i=1;i<4;i++){
        if(d == (s[i]-48)) {
            k = 1;

        } else {
            d = (s[i]-48);


        }
    }
    
    if(k==0) printf("Good\n");
    else printf("Bad\n");
    
    return 0;
}


Measured memory_bytes: 128
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, k; cin >> n >> k;
	vector<double> p(n); rep(i, n)cin >> p[i];
	vector<double> sum(n + 1);
	rep(i, n)
	{
		double exp = ((p[i] * (p[i] + 1)) / 2) / p[i];
		sum[i + 1] = sum[i] + exp;
	}
	double res = 0;
	rep(i, n - k + 1)
	{
		res = max(res, sum[i + k] - sum[i]);
	}
	printf("%.10f", res);
}

Measured memory_bytes: 3328
while True:
  l = []
  n = int(input())
  if n == 0:
    break
  lx = [0 for i in range(n+1)]
  for j in range(n):
    l1 = [int(i) for i in input().split()]
    c = 0
    for i in l1:
      c += i
    l1.append(c)
    for i in range(n+1):
      lx[i] += l1[i]
    l.append(l1)
  l.append(lx)
  for s in l:
    a = ''
    for t in s:
      a += ' ' * (5-len(str(t)))
      a += str(t)
    print(a)

Measured memory_bytes: 7628
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;


ll n, m, X;
vector< ll > g[1002];
vector< pll > t[2002];
vector< pair<ll, pll> > e;
ll used[2002];
ll p[2002];
ll fs(ll x)
{
        return p[x] == x ? x : p[x] = fs(p[x]);
}
void ms(ll x, ll y)
{
        x = fs(x);
        y = fs(y);
        p[y] = x;
}
multiset<ll> s;
ll wt;
const ll mod = 1e9 + 7;
void dfs(ll ss, ll tar, ll pr)
{
        if(ss == tar) {
                wt = *(s.rbegin()); return;
        }
        for(auto &i : t[ss]) {
                if(i.first == pr) continue;
                s.insert(i.second);
                dfs(i.first, tar, ss);
                s.erase(s.find(i.second));
        }
}
int main()
{
        cin >> n >> m >> X;
        for(ll i=1;i<=n;i++) p[i]=i;
        for(ll i=1;i<=m;i++) {
                ll u,v,x;
                cin >> u >> v >> x;
                e.pb(make_pair(x,make_pair(u , v)));
        }
        sort(e.begin(), e.end());
        ll S = 0;
        for(ll i=0;i<e.size();i++) {
                ll a = e[i].second.first;
                ll b = e[i].second.second;
                if(fs(a) == fs(b)) continue;
                ms(a , b);
                ll w = e[i].first;
                t[a].pb(make_pair(b , w));
                t[b].pb(make_pair(a , w));
                S += e[i].first;
                used[i]=1;
        }
        if(S > X){
                cout << "0\n"; return 0;
        }
        //cout << S << " " << X<< endl;
        ll eq = 0;
        ll up = 0;
        for(ll i=0;i<m;i++){
                if(used[i]) continue;
                s.clear();
                ll a = e[i].second.first;
                ll b = e[i].second.second;
                ll ww = e[i].first;
                dfs(a , b, -1);
                //wt = *s.rbegin();
                if(ww - wt == X-S) {
                        eq++;
                }else if(ww - wt > X-S) {
                        up++;
                }
        }
        ll ans = 1LL;
        vector< ll > pw(4002, 1LL);
        for(ll i=1;i<=m+10;i++) {
                pw[i] = (pw[i-1] * 2)%mod;
        }
        //cout << eq << " " << up << endl;
        ans = (pw[up] * ((pw[eq] - 1 + mod)%mod) )%mod;
        ans = (ans * 2LL)%mod;
        if(X - S == 0) {

                ll ret = (pw[n-1] - 2 + mod)%mod;
                ret = (ret * pw[m-n+1])%mod;
                ans = (ans + ret)%mod;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 512
N,M = list(map(int,input().split()))
ans = 0
pen = 0

check = {}

for i in range(M):
    p,S = input().split()
    p = int(p)
    if p not in check:
        if S == 'WA':
            check[p] = 1
        else:
            ans += 1
            check[p] = -1
    else:
        if S == 'WA' and check[p] != -1:
            check[p] += 1
        elif S == 'AC' and check[p] != -1:
            pen += check[p]
            ans += 1
            check[p] = -1

print(ans,pen)

Measured memory_bytes: 19140
#include <math.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)
#define MIN(a, b) ((a) < (b)) ? (a) : (b)
#define LLONG_MAX     9223372036854775807i64

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 29;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

ll Pow(ll a, ll b) {
	ll x = 1;
	while (b > 0) {
		if (b & 1) x = x * a;
		a = a * a;
		b = b >> 1;
	}
	return x;
}

/*<ここから>***********************************************************/


int main()
{
	string S;
	cin >> S;

	int ans = 0;
	rep(i, S.length()) {
		if (S[i] == '+')ans++;
		else ans--;
	}

	cout << ans << endl;

	return 0;
}


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

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

class modint {
	static constexpr std::int_fast64_t Modulus = 998244353;
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr operator u64() const { return a; }
};

int main() {
	ll n, s;
	cin >> n >> s;
	vector<ll> as(n);
	rep(i, n) cin >> as[i];
	vector<vector<modint>> dp(n + 1, vector<modint>(s + 1, 0));
	dp[0][0] = 1;
	rep(i, n) {
		dp[i + 1] = dp[i];
		rep(j, s + 1) {
			dp[i + 1][j] *= 2;
		}
		rep(j, s + 1) {
			ll add = j + as[i];
			if (add < s + 1) {
				dp[i + 1][add] += dp[i][j];
			}
		}
	}
	cout << dp[n][s] << endl;
	return 0;
}


Measured memory_bytes: 73660
#include <stdio.h>
#include <stdlib.h>

#define N 1000
#define MAX(A,B) ((A) < (B) ? (B) : (A))

static int x;
static int y;
static int s;

int main(int argc, char *argv[]) {
  int i, j;

  for (;;) {
    int res = 0;

    scanf("%d%d%d", &x, &y, &s);
    if (x == 0 && y == 0 && s == 0) {
      break ;
    }
    x += 100;
    y += 100;

    for (i = 1; i < N; ++i)
    for (j = 1; j < N; ++j) {
      if (i * x / 100 + j * x / 100 == s) {
	res = MAX(res, i * y / 100 + j * y / 100);
      }
    }

    printf("%d\n", res);
  }

  return (EXIT_SUCCESS);
}

Measured memory_bytes: 600
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define ll long long
#define INFTY 1 << 21



int main() {
  int X, A;
  cin >> X >> A;
  if (X < A)
    cout << 0 << endl;
  else
    cout << 10 << endl;
  return 0;
}


Measured memory_bytes: 256
import math

n = int(input())
res = float("inf")
for i in range(1, int(math.sqrt(n))+1):
    if n % i == 0 and res > max(len(str(int(n/i))), len(str(i))):
        res = max(len(str(int(n/i))), len(str(i)))

print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3004;
ll dp[N][N];
// dp(i,j) the optimal value of x-y in interval (i->j)

ll a[N];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d",&a[i]);
		dp[i][i] = a[i];
	}
	
	for(int len=2;len<=n;len++)
	{
		for(int l=1;l+len<=n+1;l++)
		{
			int r = l+len-1;
			dp[l][r] = max(a[l] - dp[l+1][r], a[r] - dp[l][r-1]);
		}
	}
	cout<<dp[1][n];
}

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

int main() {
    
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int k;
    cin>>k;
    string s;
    cin>>s;
    int l = s.length();
    string str = s.substr(0, k);
    
    if(l <= k){
        cout<<s;
    }
    else{
        cout<<str<<"."<<"."<<".";
    }
    
    cout<<"\n";
    return 0;
}


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

int main() {
  int A,B,C; cin >>A >>B >>C;
  
  if (!(A==B && B==C && C==A)){
    if(A==B || B==C || C==A) cout <<"Yes" <<endl;
    else cout <<"No";
  }else cout <<"No";
  
}


Measured memory_bytes: 256