akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int G[15][15];
bool solve()
{
    //initialization
    const int INF = 1000000;
    for(int i = 0; i < 15; i++)
        for(int j = 0; j < 15; j++)
        G[i][j] = INF;
    int n = 0, x = 0, y = 0, c = 0;
    cin >> n;
    if(n == 0) return false;
    for(int i = 1; i <= n; i++)
    {
        cin >> x >> y >> c;
        G[x][y] = G[y][x] = c;
    }
    //floyd
    for(int k = 0; k < 10; k++)
        for(int i = 0; i < 10; i++)
            for(int j = 0; j < 10; j++)
            G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
    int ans = INF, ansmt = 0;
    for(int i = 0; i < 10; i++)
    {
        int tmp = 0;
        for(int j = 0; j < 10; j++)
            if(i != j && G[i][j] != INF) tmp += G[i][j];
        if(tmp != 0 && tmp < ans) {ans = tmp; ansmt = i;}
    }
    cout << ansmt << " " << ans << endl;
    return true;
}
int main()
{
    while(solve()) ;
    return 0;
}



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

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;


long long Pow[(long long)10];
long long GetPow(long long l) {
    if (l==0) Pow[0] = 1;
   if(!Pow[l]) Pow[l] = (GetPow(l-1)*10);
   return Pow[l];
}

ll GetNum(ll a, ll b, ll n) {
    ll ans = 0;
    ll keta = 1;
    ll now = 1;
    while (n >= GetPow(keta)) keta++;
    // cout<<keta<<endl;
    rep(i,0,keta-2) ans += GetPow(i);
    if (a==b) ans += (a<=n);
    // cout<<ans<<endl;
    if (keta !=1) {
        ll max = 1;
        rep(i,0,GetPow(keta-2)) {
            if (a*GetPow(keta-1)+b+i*10 <= n) ans++;
        }
    }
    
    return ans;
}

int main(void) {
    ll N;
    cin>>N;
    ll ans = 0;
    rep(a,1,10) {
        rep(b,1,10) {
            // cout<<a<<b<<" "<<GetNum(a,b,N)<<endl;
            ans += GetNum(a,b,N) * GetNum(b,a,N);
        } 
    }
    cout<<ans<<endl;
    // cout<<GetNum(1,2,N)<<endl;




   return 0;
}

Measured memory_bytes: 256
//#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 h,w,n=0; cin>>h>>w;
    vector<vector<int>> a(h,vector<int>(w,0)),ans(h*w-1,vector<int>(4,0));
    rep(i,h)rep(j,w){
        cin>>a[i][j];
    }
    rep(i,h){
        if(i%2){
            for(int j=w-1;j>=1;j--){
                if(a[i][j]%2){
                    a[i][j]--; a[i][j-1]++;
                    ans[n]={i+1,j+1,i+1,j};
                    n++;
                }
            }
            if(i!=h-1 && a[i][0]%2){
                a[i][0]--; a[i+1][0]++;
                ans[n]={i+1,1,i+2,1};
                n++;
            }
        }
        else{
            for(int j=0;j<w-1;j++){
                if(a[i][j]%2){
                    a[i][j]--; a[i][j+1]++;
                    ans[n]={i+1,j+1,i+1,j+2};
                    n++;
                }
            }
            if(i!=h-1 && a[i][w-1]%2){
                a[i][w-1]--; a[i+1][w-1]++;
                ans[n]={i+1,w,i+2,w};
                n++;
            }
        }
    }
    cout<<n<<endl;
    rep(i,n){
        rep(j,3) cout<<ans[i][j]<<" ";
        cout<<ans[i][3]<<endl;
    }
}

Measured memory_bytes: 16768
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vl a(n+2);
    exrep(i, 1, n) {
        cin >> a[i];
    }

    ll x = 0;
    exrep(i, 0, n) {
        x += abs(a[i+1] - a[i]);
    }

    vl ans(n+1);
    exrep(i, 1, n) {
        if((a[i] - a[i-1])*(a[i] - a[i+1]) <= 0) {
            ans[i] = x;
        }
        else if(abs(a[i] - a[i-1]) < abs(a[i] - a[i+1])) {
            ans[i] = x - 2*abs(a[i] - a[i-1]);
        }
        else {
            ans[i] = x - 2*abs(a[i] - a[i+1]);
        }
    }

    exrep(i, 1, n) {
        out(ans[i]);
    }
    
    re0;
}

Measured memory_bytes: 2816
S = input()

W = {
  'SUN': 0,
  'MON': 1,
  'TUE': 2,
  'WED': 3,
  'THU': 4,
  'FRI': 5,
  'SAT': 6
}


if S in W:
  wn = W[S]
  print(7-wn)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int maxn=500009;

int n,m;
int a[maxn];
int nex[maxn],tong[maxn];

int ql[maxn],qr[maxn];
vector<int>G[maxn];
int ans[maxn];

int c[maxn];
int lowbit(int x){
	return x&(-x);
}
void Add(int x,int val){
	while(x<=n){
		c[x]+=val;x+=lowbit(x);
	}
}
int query(int x){
	int ret=0;
	while(x){
		ret+=c[x];x-=lowbit(x);
	}
	return ret;
}

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=n;i>=1;--i){
		nex[i]=tong[a[i]];
		tong[a[i]]=i;
	}
	for(int i=1;i<=m;++i){
		scanf("%d%d",&ql[i],&qr[i]);
		G[ql[i]].push_back(i);
	}
	for(int i=1;i<=n;++i)if(tong[i])Add(tong[i],1);
	for(int i=1;i<=n;++i){
		for(int j=0;j<G[i].size();++j){
			int id=G[i][j];
			ans[id]=query(qr[id]);
		}
		Add(i,-1);
		if(nex[i])Add(nex[i],1);
	}
	for(int i=1;i<=m;++i)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 38076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public final class Main {

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        final int m = fs.nextInt();
        final int mines = fs.nextInt();
        final int[] rows = new int[n + 1];
        final int[] cols = new int[m + 1];
        final Set<String> seen = new HashSet<>();
        int maxR = 0, rowIdx = -1;
        int maxC = 0, colIdx = -1;
        for (int i = 0; i < mines; i++) {
            final int x = fs.nextInt();
            final int y = fs.nextInt();
            if (++rows[x] > maxR) {
                maxR = rows[x];
                rowIdx = x;
            }
            if (++cols[y] > maxC) {
                maxC = cols[y];
                colIdx = y;
            }
            seen.add(x + "," + y);
        }
        int res = 0;
        for (int col = 1; col <= m; col++) {
            res = Math.max(res, maxR + cols[col] - (seen.contains(rowIdx + "," + col) ? 1 : 0));
        }
        for (int row = 1; row <= n; row++) {
            res = Math.max(res, maxC + rows[row] - (seen.contains(row + "," + colIdx) ? 1 : 0));
        }
        System.out.println(res);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 93356
x, y = map(lambda x: int(x), input().split(' '))

if(y % 2 == 1):
    print("No")
    exit(0)

if(y < 2*x):
    print("No")
    exit(0)

if(y > x * 4):
    print("No")
    exit(0)

print("Yes")

Measured memory_bytes: 9056
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 3000;
int r, c, k;
ll v[MAX_N][MAX_N];
ll dp[MAX_N][MAX_N][4];

int main() {
    fastio();

    cin >> r >> c >> k;
    forn(i, k) {
        int r, c, x;
        cin >> r >> c >> x;
        r--, c--;
        v[r][c] = x;
    }

    dp[0][0][1] = v[0][0];
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            if (i > 0) {
                ll x = *max_element(dp[i - 1][j], dp[i - 1][j] + 4);
                dp[i][j][0] = x;
                dp[i][j][1] = x + v[i][j];
            }

            if (j > 0) {
                chmax(dp[i][j][0], dp[i][j - 1][0]);
                chmax(dp[i][j][1], max(dp[i][j - 1][1], dp[i][j - 1][0] + v[i][j]));
                chmax(dp[i][j][2], max(dp[i][j - 1][2], dp[i][j - 1][1] + v[i][j]));
                chmax(dp[i][j][3], max(dp[i][j - 1][3], dp[i][j - 1][2] + v[i][j]));
            }
        }
    }

    cout << *max_element(dp[r - 1][c - 1], dp[r - 1][c - 1] + 4) << endl;

    return 0;
}

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

void solve()
{
    int n;
    cin >> n;
    int a[200005];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    ll ret = a[n - 1];
    int cnt = 2;
    for (int i = n - 2; i >= 0 && cnt < n; --i, cnt += 2) {
        if (cnt + 2 <= n) {
            ret += 2 * a[i];
        } else {
            ret += a[i];
        }
    }
    cout << ret << endl;
}

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

    /* int T; */
    /* cin >> T; */
    /* for (int t = 0; t < T; ++t) { */
        solve();
    /* } */
    return 0;
}


Measured memory_bytes: 4428
#include<cstdio>
using namespace std;
int main()
{
    int n,k,ans;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        ans=k;
        while(--n)
        {
            ans*=k-1;
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3232
#include <iostream>

 using namespace std;

 int main()
{
   int i, a, b, temp;
   for(i=0; i<=3000; i++)
  { 
      cin >> a >> b;
     if(a == 0 && b == 0) 
      break; 
      
      if ( a > b )
    {
        temp = a;
        a = b;
        b = temp;
    } 
     
      cout << a << " " << b << endl;
  
    
    
  } 
  
} 


Measured memory_bytes: 3084
#include <stdio.h>
int main(void){
    int tmp,j,n,i,f=0,a[100],A=0,B=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
    	scanf(" %d",&a[i]);
    }
    for(i=0;i<n-1;i++){
    	for(j=i;j<n;j++){
    		if(a[i]<a[j]){
    			tmp=a[i];
    			a[i]=a[j];
    			a[j]=tmp;
    		}
    	}
    }
    for(i=0;i<n;i++){
    	if(f==0){
    		A+=a[i];
    		f=1;
    	}else{
    		B+=a[i];
    		f=0;
    	}
    }
    printf("%d\n",A-B);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
  int n;
  int i,j;
  int data[10][10];
  int isum[10];
  int jsum[10];
  int result;

  while(1)
    {
      /* ú» */
      for(i = 0 ; i < 10 ; i++)
	{
	  isum[i] = 0;
	  jsum[i] = 0;
	}
      result = 0;
      
      /* üÍ  */
      scanf("%d",&n);
      if(n == 0) break;
      
      for(i = 0 ; i < n ; i++)
	{
	  for(j = 0 ; j < n ; j++)
	    {
	      scanf("%d",&data[i][j]);
	    }
	}
      
      /* vZ */
      for(i = 0 ; i < n ; i++)
	{
	  for(j = 0 ; j < n ; j++)
	    {
	      isum[i] += data[j][i];
	    }
	}
      for(j = 0 ; j < n ; j++)
	{
	  for(i = 0 ; i < n ; i++)
	    {
	      jsum[j] += data[j][i];
	    }
	}
      
      for(i = 0 ; i < n ; i++)
	{
	  result += isum[i];
	}
      
      /* oÍ */
      for(i = 0 ; i < n ; i++)
	{
	  for(j = 0 ; j < n ; j++)
	    {
	      printf("%5d",data[i][j]);
	      if(j == n-1) printf("%5d",jsum[i]);
	    }
	  printf("\n");
	}
      
      for(i = 0 ; i < n ; i++)
	{
	  printf("%5d",isum[i]);
	}
      printf("%5d\n",result);
    }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,x;
    cin>>n;
    long long int a[n+10];
    int f=1;
    for(long long int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(long long int i=0; i<n; i++)
    {


        if(a[i]%2==0)
        {
            if(a[i]%3!=0&&a[i]%5!=0)
            {
                cout<<"DENIED"<<endl;
                f=0;
                break;
            }

        }

    }
    if(f==1)
    {
        cout<<"APPROVED"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define fgx cerr<<"-------------"<<endl
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
void dbg(){cerr<<endl;}
template<typename A,typename... B>void dbg(A x,B... y){cerr<<x<<" ";dbg(y...);}
#define debug(...) cerr<<#__VA_ARGS__<<"=",dbg(__VA_ARGS__)
int pl[5050],g[5050],a[5050]; ll f[5050][5050];
inline void gao(ll &x,ll y){x=min(x,y);}
int main()
{	int tmp,n,i,j,A,B; ll ans=1e18;
	scanf("%d%d%d",&n,&A,&B);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
	{
		pl[a[i]]=i;
		for(j=i-1;j;j--)
			if(a[j]>a[i])
				g[i]++;
	}
	for(i=1;i<=n;i++)
		for(j=0;j<=n;j++)
			f[i][j]=1e18;
	f[0][0]=0; 
	for(i=0;i<n;i++)
	{
		tmp=pl[i+1];
		for(j=0;j<=n;j++)
		{
			if(j>g[tmp]) gao(f[i+1][j-1],f[i][j]+A);
			else gao(f[i+1][j],f[i][j]+B),gao(f[i+1][g[tmp]],f[i][j]);
		}
	}
	for(i=0;i<=n;i++) gao(ans,f[n][i]);
	cout<<ans;
	return 0;
}



Measured memory_bytes: 198912
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Problem solver = new Problem();
        solver.solve(0, in, out);
        out.close();
    }

    static class Problem {

        private int count;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt(), M = in.nextInt();
            Map<Integer, List<Integer>> graph = new HashMap<>();

            for (int i = 0; i < N; i++) {
                graph.put(i, new ArrayList<>());
            }

                for(int i = 0; i < M; i++) {
                int u = in.nextInt() - 1, v = in.nextInt() - 1;
                graph.get(u).add(v);
                graph.get(v).add(u);
            }

            boolean[] marked = new boolean[N];
            int res = 0;
            for (int i = 0; i < N; i++) {
                if(!marked[i]) {
                    count = 0;
                    dfs(graph, i, marked);
                    res = Math.max(res, count);
                }
            }

            out.println(res);
        }

        public void dfs(Map<Integer, List<Integer>> graph, int s, boolean[] marked) {
            marked[s] = true;
            count++;
            for(int v : graph.get(s)) {
                if(!marked[v])
                    dfs(graph, v, marked);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 121800
#include "bits/stdc++.h"
using namespace std;

void solve(){
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    vector <int> dp(n, INT_MAX);
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j <= i + k; ++j){
            if(j < n){
                dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
            }
        }
    }
    cout << dp[n-1];
}

int main() {
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
    #endif
    */
    solve();
    return 0;
}

Measured memory_bytes: 1024
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

import sys

N, Q = [int(i) for i in input().split()]
tree = [[] for i in range(N)]
cost_ls = [0 for i in range(N)]
for i in range(N - 1):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

yet = set()


def plus(node, num):
    yet.add(node)
    cost_ls[node] += num
    if len(tree[node]) == 0:
        return
    for child in tree[node]:
        if child in yet:
            continue
        plus(child, cost_ls[node])


for i in range(Q):
    p, x = [int(i) for i in sys.stdin.readline().split()]
    cost_ls[p - 1] += x

plus(0, 0)

print(" ".join([str(cost) for cost in cost_ls]))

Measured memory_bytes: 241924
#include <bits/stdc++.h>
using namespace std;
int H,W,N;
char Map[1010][1010];
int Si[10];
int Sj[10];
int ans=0;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int dis[1010][1010];
int bfs(int i)
{
    memset(dis,-1,sizeof(dis));
    P S=make_pair(Si[i],Sj[i]);
    dis[Si[i]][Sj[i]] = 0;
    P E=make_pair(Si[i+1],Sj[i+1]);
    queue<P> q;
    q.push(S);
    while(q.size())
    {
        P next=q.front();
        q.pop();
        if(next.first==Si[i+1]&&next.second==Sj[i+1])
            break;
        for(int i=0;i<4;i++)
        {
            int nx=next.first+dx[i];
            int ny=next.second+dy[i];
            if(dis[nx][ny]<0&&nx>=1&&nx<=H&&ny>=1&&ny<=W&&Map[nx][ny]=='.')
            {
                q.push(P(nx,ny));
                dis[nx][ny]=dis[next.first][next.second]+1;
            }
        }
    }
    return dis[E.first][E.second];

}
int main()
{
    scanf("%d%d%d",&H,&W,&N);
    getchar();
    for(int i=1;i<=H;i++)
    {
        for(int j=1;j<=W;j++)
        {
            scanf("%c",&Map[i][j]);
            if(Map[i][j]=='S')
            {
                Si[0]=i;
                Sj[0]=j;
                Map[i][j]='.';
            }
            else if(isdigit(Map[i][j]))
            {
                Si[Map[i][j]-48]=i;
                Sj[Map[i][j]-48]=j;
                Map[i][j]='.';
            }
        }
        getchar();
    }
    for(int i=0;i<N;i++)
    {
        //cout<<i<<": "<<bfs(i)<<endl;
        ans+=bfs(i);
    }
    printf("%d\n",ans);


    return 0;
}



Measured memory_bytes: 8196
import numpy as np

n, m = map(int, input().split())
adj = np.zeros((n, n), dtype=np.bool)
for _ in range(m):
  s, t = map(int, input().split())
  adj[s-1, t-1] = True
deg = adj.sum(axis=1)

ev = np.zeros(n, dtype=np.float)
for i in range(n - 2, -1, -1):
  ev[i] = ev[adj[i]].mean() + 1.

prob = np.zeros(n, dtype=np.float)
prob[0] = 1.
for i in range(n - 1):
  prob[adj[i]] += prob[i] / deg[i]

decrease = 0.
for i in np.where(deg > 1)[0]:
  now = ev[adj[i]].mean()
  cut = (ev[adj[i]].sum() - ev[adj[i]].max()) / (deg[i] - 1)
  decrease = np.maximum(decrease, (now - cut) * prob[i])
    
print(ev[0] - decrease)


Measured memory_bytes: 12876
#include <cstdio>
using namespace std;
int H, W; char s[109][10009];
int main() {
	scanf("%d%d", &W, &H);
	for (int i = 0; i < H; i++) scanf("%s", s[i]);
	int lcnt = 0, rcnt = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == 'W') rcnt++;
		}
	}
	int ret = 0, sum = 999999999;
	for (int i = 0; i <= W; i++) {
		if (sum > lcnt + rcnt) sum = lcnt + rcnt, ret = i;
		if (i == W) continue;
		for (int j = 0; j < H; j++) {
			if (s[j][i] == 'E') lcnt++;
			if (s[j][i] == 'W') rcnt--;
		}
	}
	printf("%d %d\n", ret, ret + 1);
	return 0;
}

Measured memory_bytes: 3700
#include<stdio.h>

int main(){
    int n,x;
    int b,i,j,k,a;
    while(1){
        scanf("%d %d",&n,&x);
        b=0;
        if(n==0 && x==0){
            break;
        }
        for(k=1;k<=n;k++){
            for(j=1;j<=n;j++){
                for(i=1;i<=n;i++){
                    if(i==j||j==k||i==k){}
                    else{
                        a=i+j+k;
                        if(a==x){
                            b+=1;
                        }
                    }
                }
            }
        }
        printf("%d\n",b/6);
    }
    return 0;
}


Measured memory_bytes: 2052
A_1 = list(map(int, input().split()))
A_2 = list(map(int, input().split()))
A_3 = list(map(int, input().split()))
N = int(input())
b = [(int(input())) for _ in range(N)]
Z_1 = [0, 0, 0]
Z_2 = [0, 0, 0]
Z_3 = [0, 0, 0]
for i in range(3):
    for j in range(N):
        if A_1[i] == b[j]:
            Z_1[i] = 1
        elif A_2[i] == b[j]:
            Z_2[i] = 1
        elif A_3[i] == b[j]:
            Z_3[i] = 1


if Z_1[0] == Z_1[1] == Z_1[2] == 1:
    print("Yes")
elif Z_2[0] == Z_2[1] == Z_2[2] == 1:
    print("Yes")
elif Z_3[0] == Z_3[1] == Z_3[2] == 1:
    print("Yes")
elif Z_1[0] == Z_2[0] == Z_3[0] == 1:
    print("Yes")
elif Z_1[1] == Z_2[1] == Z_3[1] == 1:
    print("Yes")
elif Z_1[2] == Z_2[2] == Z_3[2] == 1:
    print("Yes")
elif Z_1[0] == Z_2[1] == Z_3[2] == 1:
    print("Yes")
elif Z_1[2] == Z_2[1] == Z_3[0] == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;
	while (cin >> xa1 >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2)
	{
		if (xa1 > xa2)
			swap(xa1, xa2);
		if (ya1 > ya2)
			swap(ya1, ya2);
		if (xb1 > xb2)
			swap(xb1, xb2);
		if (yb1 > yb2)
			swap(yb1, yb2);
		if (xb1 <= xa1&&xa1 <= xb2 || xb1 <= xa2&&xa2 <= xb2 || xa1 <= xb1&&xb1 <= xa2 || xa1 <= xb2&&xb2 <= xa2) {
			if (yb1 <= ya1&&ya1 <= yb2 || yb1 <= ya2&&ya2 <= yb2 || ya1 <= yb1&&yb1 <= ya2 || ya1 <= yb2&&yb2 <= ya2) {
				cout << "YES";
			}
			else cout << "NO";
		}
		else cout << "NO";
		cout << endl;
	}
	return 0;
}

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

typedef pair<int,int> PII;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 200000 + 5;

int n, m, q;
PII st;
char s[maxn], t[maxn];
int dp[maxn][4];

int main() {
    scanf("%d%d%d%d%d%s%s", &n, &m, &q, &st.first, &st.second, s + 1, t + 1);
    int x = st.first, y = st.second, flag = 0;
    for (int i = 1; i <= q; i++) {
        if (s[i] == 'L') y--;
        if (y == 0) flag = 1;
        if (t[i] == 'R' && y != m) y++;
    }
    y = st.second;
    for (int i = 1; i <= q; i++) {
        if (s[i] == 'R') y++;
        if (y == m + 1) flag = 1;
        if (t[i] == 'L' && y != 1) y--;
    }
    for (int i = 1; i <= q; i++) {
        if (s[i] == 'U') x--;
        if (x == 0) flag = 1;
        if (t[i] == 'D' && x != n) x++;
    }
    x = st.first;
    for (int i = 1; i <= q; i++) {
        if (s[i] == 'D') x++;
        if (x == n + 1) flag = 1;
        if (t[i] == 'U' && x != 1) x--;
    }
    if (flag) puts("NO");
    else puts("YES");
    return 0;
}


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

int main(){
	int n,m;
	int A[100][100];
	int b[100];
	int c[100];
	cin >> n >> m;
	for(int i=0;i<n;i++) c[i]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin >> A[i][j];
		}
	}
	for(int i=0;i<m;i++){
		cin >> b[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			c[i]+=A[i][j]*b[j];
		}
	}
	for(int i=0;i<n;i++) cout<<c[i] <<endl;

	return 0;
}

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

int main()
{
    int n, x[201], count = 0;
    bool odd = true;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    while (odd == true)
    {
        for (int i = 0; i < n; i++)
        {
            if (x[i] % 2 == 0)
            {
                odd = true;
            }
            else
            {
                odd = false;
                break;
            }
            if (odd == true && i == n - 1)
            {
                for (int i = 0; i < n; i++)
                {
                    x[i] = x[i] / 2;
                }
                count++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

alias Point = Tuple!(double, "x", double, "y");

void main() {
    auto xs = reads!double;

    auto a = Point(xs[0], xs[1]);
    auto b = Point(xs[2], xs[3]);

    auto d = sqrt((a.x - b.x) ^^ 2 + (a.y - b.y) ^^ 2);
    writefln("%.6f", d);
}


Measured memory_bytes: 2624
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MOD 1000000007

LL powmod(LL a, LL n){
	if(n == 0) return 1;
	if(n % 2) return (a*powmod(a,n-1)) % MOD;
	LL c = powmod(a,n/2);
	return (c*c) % MOD;
}

LL inv(LL a){
	return powmod(a,MOD-2);
}

char stuff[1100][1100];

int main(){
	LL h, w, k;
	scanf("%lld%lld%lld", &h, &w, &k);
	for(int i = 0; i < h; i++){
		scanf("%s", stuff[i]);
	}
	if(k == 0){
		cout << 1 << endl;
		return 0;
	}
	k--;
	int vq = 0;
	int hq = 0;
	for(int i = 0; i < h; i++){
		if(stuff[i][0]=='#' && stuff[i][w-1]=='#'){
			hq = 1;
		}
	}
	for(int i = 0; i < w; i++){
		if(stuff[0][i]=='#' && stuff[h-1][i]=='#'){
			vq = 1;
		}
	}
	if(vq && hq){
		cout << 1 << endl;
		return 0;
	}
	LL c, a, e;
	c = a = e = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(stuff[i][j]=='#'){
				c++;
			}
		}
	}
	if(!vq && !hq){
		cout << powmod(c,k) << endl;
		return 0;
	}
	if(vq){
		for(int i = 0; i < 1050; i++){
			for(int j = 0; j < i; j++){
				swap(stuff[i][j],stuff[j][i]);
			}
		}
		swap(h,w);
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w-1; j++){
			if(stuff[i][j]=='#' && stuff[i][j+1]=='#'){
				a++;
			}
		}
		if(stuff[i][0]=='#' && stuff[i][w-1]=='#'){
			e++;
		}
	}
	LL ans1 = powmod(c,k);
	if(a == 0 || c == e){
		cout << ans1 % MOD << endl;
		return 0;
	}
	LL ans2 = powmod(c,k)-powmod(e,k);
	ans2 %= MOD;
	ans2 *= inv(c-e);
	ans2 %= MOD;
	ans1 -= a*ans2;
	ans1 %= MOD;
	while(ans1 < 0) ans1 += MOD;
	cout << ans1 << endl;
	return 0;
}


Measured memory_bytes: 1408
N = int(input())

tb = [[0] * 9 for i in range(9)]

for i in range(1, N+1):
  head = int(str(i)[0])
  tail = int(str(i)[-1])

  if head > 0 and tail > 0:
    tb[head-1][tail-1] += 1

ans = 0
for i in range(9):
  #print(tb[i])
  for j in range(9):
    ans += tb[i][j] * tb[j][i]

print(ans)

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

#define ll long long 

int main(){
	ll n,x,t=0,sum=0,mx=-1;
	cin>>n; ll a[n],i;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	if(n==1)
	cout<<"0\n";
	else{
		for(i=1;i<n;i++){
			if(a[i]<a[i-1]){
				ll temp=i-1;
				while((i<n)&&(a[i]<=a[temp])){
					sum+=(a[temp]-a[i]);
					i++;
				}
				i--;
			}
			
		}
		cout<<sum<<"\n";		
	}

	return 0;
}

Measured memory_bytes: 5108
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int pre;
    cin >> pre;
    ll sum = 0;
    for(int i = 1; i < n; ++i)
    {
        int nxt;
        cin >> nxt;
        if(nxt < pre)
        {
            sum += (pre - nxt);
            pre = (pre-nxt);
            pre += nxt;
        }
        else
        {
            pre = nxt;
        }
    }
    cout << sum;
	return 0;
}

Measured memory_bytes: 3548
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
const int N = 1e5+5; 
int a[N]={0},f[N]={0};
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("text1.in","r",stdin);
	//freopen("text1.out","w",stdout);
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=k;i++){
		int u,v;
		cin>>u>>v;
		if(a[u]>a[v]){
			f[v]=1;
		}
		else if(a[u]<a[v]){
			f[u]=1;
		}
		else f[u]=f[v]=1;
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(f[i]==0) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 4432
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

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

    int len = s.size();
    int ans = 1e9;
    for (int i = 0; i <= len - 3; i++) {
        int tmp = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
        ans = min(ans, abs(tmp - 753));
    }
    cout << ans << endl;
}


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

#define F first
#define S second

#define debug(x) cerr << #x << " : " << x << endl;

#define _all(x) x.begin(), x.end()
#define _sz(x) ((int)x.size())

typedef long long ll;


// code //


void solve() {
	
	
}

int main() {
	int x, t, n;
	cin >> n >> x >> t;
	int num = ceil((double)n/x);
	cout << num*t;
}


Measured memory_bytes: 3632
#include <stdio.h>
 
char s[100][105];
char tmp[105];
int idx;
int N, L;
 
int main(void)
{
  int i, j, k;
  
  scanf("%d %d\n", &N, &L);
  for (i = 0; i < N; ++i)
  {
    scanf("%s\n", s[i]);
  }
  
  for (i = 0; i < N; ++i)
  {
    idx = i;
    for (j = i+1; j < N; ++j)
    {
      for (k = 0; k < L; ++k)
      {
        if (s[idx][k] > s[j][k])
        {
          idx = j;
          break;
        }
        else if (s[idx][k] < s[j][k]) break;
      }
    }
    for (k = 0; k < L; ++k)
    {
      tmp[k] = s[idx][k];
      s[idx][k] = s[i][k];
      s[i][k] = tmp[k];
    }
    printf("%s", s[i]);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <string>
#include<iostream>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int k=a.length(),q=0;
	for(int i=0;i<=k;i++)
 {
	if(a[i]=='C')
		q=1;//标记Ｃ的位置
	if(q) 
	if(a[i]=='F')
      {
	cout<<"Yes"<<endl;
		return 0;
	}
		}	
	cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

const int MAXN = 22;
const int MASK = (1 << 21);
const int MOD = 1e9 + 7;

int n, m;
int a[MAXN][MAXN];
int T[MAXN][MASK];

int rec(int index, int mask)
{
    if(T[index][mask] != -1)
    {
        return T[index][mask];
    }
    if(mask == m)
    {
        return 1;
    }
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(a[index][i] && !(mask & (1 << i)))
        {
            ans += rec(index + 1, mask | (1 << i));
            ans %= MOD;
        }
    }
    return T[index][mask] = ans;
}

void solve()
{
    m = (1 << n) - 1;
    memset(T, -1, sizeof(T));
    printf("%d\n", rec(0, 0));
}

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

    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            scanf("%d", &a[i][j]);

    solve();

    return 0;
}


Measured memory_bytes: 180352
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;
 use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;

procedure main is
   N: Integer;
   M: Integer;
begin
   get(N);
   get(M);
   put(6 - N - M);
end main;

Measured memory_bytes: 3700
n = int(input())
yokolist = list(map(int, input().split()))

count = 0
for i in range(n-2):
    for j in range(i,n-1):
        for k in range(j,n):
            x = yokolist[i]
            y = yokolist[j]
            z = yokolist[k]
            if x != y and y != z and z != x:
                if x < y + z and y < x + z and z < x+ y:
                    count += 1

print(count)

Measured memory_bytes: 9196
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();
            Set<Character> s = new HashSet<>();

            for (int i = 0; i < S.length(); i++) {
                s.add(S.charAt(i));
            }

            if (S.length() == s.size()) {
                out.println("yes");
            } else {
                out.println("no");
            }

        }

    }
}



Measured memory_bytes: 21844
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

int main(void) {
	int N;
	scanf("%d", &N);
	int x[10], y[10];
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &x[i], &y[i]);
	}
	double sum = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			// cout << i << " " << j << "\n";
			sum += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
		}
	}
	int factorial = 1;
	for (int i = 1; i <= N; i++) {
		factorial *= i;
	}
	// cout << factorial << "\n";
	printf("%.10lf\n", (factorial / N / (N - 1)) * (N - 1) * 2 * sum / factorial);
	return 0;
}


Measured memory_bytes: 3856
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

DIV = 10**9+7

K, S = ints_raw()

ans = 0 
for X in xrange(K+1):
    for Y in xrange(K+1):
        Z = S-X-Y
        if Z>=0 and Z<=K:
            ans+=1

print ans








Measured memory_bytes: 2568
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split())) 
d = []

for i in range(n):
    d.append(a[i]-b[i])
d.sort()

sl = 0
ans = 0
for di in d:
    if di < 0:
        sl += di
        ans += 1
    else:
        break

if sl == 0:
    print(0)
    exit()

sr = 0
for di in reversed(d):
    if di >= 0 and sr +sl < 0:
        sr += di
        ans += 1

if sr + sl >= 0:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 23940
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
#include <string.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

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

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll y) {
  ll r = 1;
  while (y) {
    if (y & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    y >>= 1;
  }
  return r;
}

// Rolling Hash
struct RollingHash {
  static const int base1 = 1007, base2 = 2009;
  static const int mod1 = 1000000007, mod2 = 1000000009;
  vector<ll> hash1, hash2, power1, power2;

  RollingHash(const string& S) {
    int n = S.size();
    hash1.resize(n+1);
    hash2.resize(n+1);
    power1.assign(n+1, 1);
    power2.assign(n+1, 1);
    rep(i, n) {
      hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
      hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
      power1[i+1] = (power1[i] * base1) % mod1;
      power2[i+1] = (power2[i] * base2) % mod2;
    }
  }

  // get hash of S[left:right]
  inline pair<ll, ll> get(int l, int r) const {
    ll res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
    if (res1 < 0) res1 += mod1;
    ll res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
    if (res2 < 0) res2 += mod2;
    return {res1, res2};
  }

  // get lcp of S[a:] and T[b:]
  inline int getLCP(int a, int b) const {
    int len = min((int)hash1.size()-a, (int)hash1.size()-b);
    int low = 0, high = len;
    while (high - low > 1) {
      int mid = (low + high) >> 1;
      if (get(a, a+mid) != get(b, b+mid)) high = mid;
      else low = mid;
    }
    return low;
  }
};

int main(int argc, char** argv) {
  int N;
  cin >> N;
  string S;
  cin >> S;

  RollingHash rh(S);

  int ans = 0;
  rep(i, N) {
    for (int j = i + 1; j < N; ++j) {
      int lcp = rh.getLCP(i, j);
      lcp = min(lcp, j - i);
      ans = max(ans, lcp);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>

int main()
{
	double a, b, c;
	while (std::cin >> a >> b >> c) {
		if (a == -1 && b == -1 && c == -1) {
			break;
		}
		else if (a == -1 || b == -1) {
			std::cout << "F" << std::endl;
		}
		else if (a + b >= 80) {
			std::cout << "A" << std::endl;
		}
		else if (a + b >= 65 && a + b < 80) {
			std::cout << "B" << std::endl;
		}
		else if (a + b >= 50 && a + b < 65) {
			std::cout << "C" << std::endl;
		}
		else if (a + b >= 30 && a + b < 50) {
			if (c >= 50) {
				std::cout << "C" << std::endl;
			}
			else {
				std::cout << "D" << std::endl;
			}
		}
		else if (a + b < 30) {
			std::cout << "F" << std::endl;
		}
	}
    return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 2e9
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

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

	vector<int>a(N);
	vector<int>ans(N,0);
	rep(i,0,N-1)cin >> a[i];
	
	rep(i, 1, N)
	{
		ans[a[i-1]-1]++;
	}
	rep(i, 0, N)cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 4812
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
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; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	ll n,sum1 = 0,sum2 = 0;
	cin >> n;
	vector<vector<ll>>a(2, vector<ll>(n));
	rep(i, 2) {
		rep(k, n) {
			cin >> a[i][k];
		}
	}
	vector<ll>cnt;
	sum1 = accumulate(all(a[0]),0LL);
	rep(i, n) {
		cnt.push_back(sum1 - accumulate(a[0].begin()+(i+1), a[0].end(),0LL) + accumulate(a[1].begin()+i,a[1].end(),0LL));
	}
	cout << *max_element(all(cnt)) << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int N;
	cin >> N;

	int h[N];
	rep(i, N) cin >> h[i];

	ll ans = 0;
	for(int i = 1; i <= 100; i++){
		bool flg = false;
		for(int j = 0; j < N; j++){
			if(h[j] < i){
				if(flg) {
					ans++;
					flg = false;
				}
			}else{
				flg = true;
			}
		}
		if(flg) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];
	
	int f=0;
	for(int i=1;i<=n-1;i++)
		if(a[i]<a[i+1]){
			swap(a[i],a[i+1]);
			f++;
		}
	cout<<n-f<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 10e9+5;
int main(void){
    int n;
    cin>>n;
    vector<int>arr(n);
    vector<int>dp(n,INF);
    for(auto &i:arr){
        scanf("%d",&i);
    }
    dp[0]=0;
    for(int i=0; i<n; ++i){
        for(auto j:{i+1,i+2}){
            if(j<n){
                dp[j] = min(dp[j],dp[i]+abs(arr[j]-arr[i]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

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

int N;
char S[100010];
int ans = 0;

int main()
{
    scanf("%d %s",&N,S);
    int now = 0;
    for(int i = 0; i < N; i++)
    {
        if(S[i] == 'I')now++;
        else now--;
        ans = max(ans,now);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int n;
  cin >> n;
  const int maxn = 1e6;

  //aが5000の時bはどの範囲までありえる？？？
  ll ans = 0;
  for (ll i = 1; i <= maxn; i++) {
    ll l = 0, r = maxn;
    while (r - l > 1) {
      ll mid = (l + r) / 2;
      if (i * mid < n) l = mid;
      else r = mid;
    }
    ans += l;
  }

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


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println(a + b >= 24 ? a + b - 24 : a + b);
	}
}

Measured memory_bytes: 35736
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000;
#define MAX_V 330

long double pi = 3.1415926535897932384626;
long double d = 180.00000;

typedef long long ll;

int main(void) {
  long double a, b, x;
  cin >> a >> b >> x;
  if (x >= (a * a * b) / 2) {
    cout << setprecision(8) << atan2((a * a * b - x), (a * a * a) / 2.0) * d / pi  << endl;
  } else {
    cout << setprecision(8) << 90.000 - atan2(2 * x, a * b * b) * d / pi << endl;
  }

  return 0;
}


Measured memory_bytes: 256
<?php
while(list($a,$op,$b) = explode(" ",trim(fgets(STDIN)))){
    
    if($op == "?"){
        break;
    }else{
        if($op == "+"){
            $ans = $a + $b;
        }elseif($op == "-"){
            $ans = $a - $b;
        }elseif($op == "*"){
            $ans = $a * $b;
        }elseif($op == "/"){
            $ans = floor($a / $b);
        }
        echo $ans .PHP_EOL;
    }
}

Measured memory_bytes: 15348
N = gets.to_i

#禁止されるパターン
# (AGCT) = (0123)として
# .012, .102, .021, 0.12, 01.2の5パターン

dp = Array.new(N+1){Array.new(4){Array.new(4){Array.new(4,0)}}}

# n = 0なら場合の数は一通り
# n = 0は根になるので、一個だけ初期化
dp[0][3][3][3] = 1


N.times do |n|
  4.times do |p3|
    4.times do |p2|
      4.times do |p1|
        4.times do |a|
          if ![p3,p2,p1,a].join.match(/.012|.102|.021|0.12|01.2/)
            dp[n+1][p2][p1][a] += dp[n][p3][p2][p1]
            dp[n+1][p2][p1][a] %= (10**9+7)
          end
        end
      end
    end
  end
end

cnt = 0
4.times do |p3|
  4.times do |p2|
    4.times do |p1|
      cnt += dp[N][p3][p2][p1]
      cnt %= (10**9 + 7)
    end
  end
end

p cnt

Measured memory_bytes: 2556
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

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

	ll n, w, m, k, ans = 0;
	string s, t;
	cin >> s >> t;
	vvll dp(s.size()+1, vll(t.size()+1, 0));
	rep(i, s.size()) {
		rep(j, t.size()) {
			if (s[i] == t[j]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i+1][j]);
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j+1]);
		}
	}
	string res = "";
	ll i = s.size(), j = t.size();
	while (i > 0 && j > 0) {
		if (dp[i][j] == dp[i - 1][j]) i--;
		else if (dp[i][j] == dp[i][j - 1]) j--;
		else {
			res = s[i - 1] + res;
			i--, j--;
		}
	}
	cout << res << endl;
	return 0;
}


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

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


Measured memory_bytes: 3084
def main():
    n = int(input())
    seq = [int(a) for a in input().split()]
    q = int(input())

    for _ in range(q):
        b, e, t = map(int, input().split())
        for k in range(e-b):
            tmp = seq[t+k]
            seq[t+k] = seq[b+k]
            seq[b+k] = tmp
    print(*seq)

main()



Measured memory_bytes: 5840