akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
   
    int K,P,N;

    scanf ("%d",&N);

    while (N > 0){

        scanf ("%d",&K);
        scanf ("%d",&P);

        if (K % P == 0)
            printf ("%d\n",P);
        else
            printf ("%d\n",K % P);
        N--;
    }

    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;

int main(){
  int N;
  cin >>N;
  vector<int> p(N);
  rep(i,N) cin >> p[i];
  sort(p);
  p[N-1] /= 2;
  int ans;
  rep(i,N) ans += p[i];
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        FastScanner in = new FastScanner(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, FastScanner in, PrintWriter out) {
            int n = in.ni();
            int[] a = in.na(n);
            HashMap<Integer, LinkedList<Integer>> map = new HashMap<>(n);
            for (int i = 0; i < n; i++) {
                LinkedList<Integer> update = map.computeIfAbsent(a[i], k -> new LinkedList<>());
                update.add(i);
            }
            int ans = 0;
            for (int j = 30; j > 0; j--) {
                int pow = 1 << j;
                //System.out.println("pow = " + pow);
                for (int i = 0; i < n; i++) {
                    LinkedList<Integer> cur = map.get(a[i]);
                    if (cur.size() == 0)
                        continue;
                    LinkedList<Integer> pairs = map.get(pow - a[i]);
                    if (pairs != null && pairs.size() > 0) {
                        if (pow - a[i] == a[i] && pairs.size() == 1)
                            continue;
                        pairs.poll();
                        cur.poll();
                        ans++;
                    }

                }
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

        public int[] na(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = ni();
            return a;
        }

    }
}



Measured memory_bytes: 105388
#include <stdio.h>
int main()
{
    int ch[14];
    ch[1] = 14;
    for(int i = 2 ; i < 14 ; i++)
    {
        ch[i] = i;
    }
    int A,B;
    scanf("%d %d",&A,&B);
    if(ch[A] > ch[B])
    {
        printf("Alice");
    }
    else if(ch[A] == ch[B])
    {
        printf("Draw");
    }
    else
        printf("Bob");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=100005;
int n,d[N],he,ta,que[N],val[N],f[N],res;bool ban[N];char s[N];
int pp,lnk[N],nxt[N*2],to[N*2];
void ae(int k1,int k2){to[++pp]=k2,nxt[pp]=lnk[k1],lnk[k1]=pp;}
void dfs(int k1,int k2){
	f[k1]=val[k1];
	for(int i=lnk[k1];i;i=nxt[i])if(to[i]!=k2){
		dfs(to[i],k1);
		res=max(res,f[k1]+f[to[i]]),f[k1]=max(f[k1],f[to[i]]+val[k1]);
	}
}
int main(){
	scanf("%d",&n);
	rep(i,2,n){
		int k1,k2;scanf("%d%d",&k1,&k2);
		ae(k1,k2),ae(k2,k1);
		++d[k1],++d[k2];
	}
	scanf("%s",s+1);
	rep(i,1,n)if(d[i]<=1&&s[i]=='B')que[++ta]=i;
	while(he!=ta){
		int k1=que[++he];ban[k1]=1;
		for(int i=lnk[k1];i;i=nxt[i])if(--d[to[i]]==1&&s[to[i]]=='B')que[++ta]=to[i];
	}
	if(ta==n)return puts("0"),0;
	if(ta==n-1)return puts("1"),0;
	int ans=2*(n-ta-1),rt=0;
	rep(i,1,n)if(!ban[i])ans+=val[i]=(d[i]^(s[i]=='W'))&1,rt=i;
	dfs(rt,0);
	printf("%d\n",ans-res*2);
	return 0;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
int dp[1001][1001],wait[1001],value[1001];
int power(int n)
{
    int num=1;
    for(int i=1;i<=n;i++)num*=10;
    return num;
}
int main()
{
    int n,w,point,num=1,wa=0;
    char c;
    while(cin>>w&&w!=0){
        cin>>n;
        for(int i=0;i<n;i++)cin>>value[i]>>c>>wait[i];
        memset(dp,0,sizeof(dp));
        for(int i=n-1;i>=0;i--){
            for(int j=0;j<=w;j++){
                if(j<wait[i])dp[i][j]=dp[i+1][j];
                else dp[i][j]=max(dp[i+1][j],dp[i+1][j-wait[i]]+value[i]);
            }
        }
        int wa=0,point=0;
        for(int i=0;i<=w;i++)if(dp[0][wa]<dp[0][i])wa=i;
        cout<<"Case "<<num<<":\n"<<dp[0][w]<<endl<<wa<<endl;
        num++;
    }
}

Measured memory_bytes: 5092
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}
 
int main() {
 int n;
 cin>>n;
 vector<int>a(n);
 deque<int>b;
 for(int i=0;i<n;i++){
   cin>>a[i];
 }
 for(int i=0;i<n;i++){
   if(i%2==(n-1)%2){b.push_front(a[i]);}
   if(i%2!=(n-1)%2){b.push_back(a[i]);}
 } 
 for(int i=0;i<n;i++){
   cout<<b[i];
   if(i<n-1){cout<<" ";}
 }
 cout<<endl;
  return 0;
}

Measured memory_bytes: 4788
import sys
s=input()
if len(s)==1:
  print(-1,-1)
elif s[0]==s[1]:
  print(1,2)
else:
  a=s[0]
  b=s[1]
  for i in range(2,len(s)):
    if s[i]==a:
      print(i-1,i+1)
      sys.exit()
    elif s[i]==b:
      print(i,i+1)
      sys.exit()
    else:
      a=b
      b=s[i]
  print(-1,-1)

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

for i in range(100):
    if 2 ** i > N:
        num = i
        break
n = num
ans = []
N = N - 1
n_rev_list = list(range(2,n+1))[::-1]
for num in n_rev_list:
    if  N % 2 == 0:
        ans.append("{} {} {}".format(1,num,N))
        ans.append("{} {} {}".format(num - 1,num,0))
        ans.append("{} {} {}".format(num - 1,num, N // 2 ))
        N = N // 2 - 1
    else:
        ans.append("{} {} {}".format(num - 1,num,0))
        ans.append("{} {} {}".format(num - 1,num, (N + 1 )// 2))
        N = (N - 1) // 2
K = len(ans)
print("{} {}".format(n,K))
for a in ans:
    print(a)

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

using namespace std;

typedef long long ll;
typedef long double ld;
const ll INF = 1e10;
const ld eps = 1e-9, pi = acos(-1.0);
typedef pair<ll, ll> P;

int main(){
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
/*
AizuOnline A0022
Maximum Sum Sequence
*/
#include <stdio.h>

#define WIDTH 8
#define HEIGHT 8
#define TETOROS 7
char heimen[HEIGHT][WIDTH+1];
int tetoro[7][3][2]={{{0,1},{1,0},{1,1}},
		 {{1,0},{2,0},{3,0}},
		 {{0,1},{0,2},{0,3}},
		 {{1,-1},{1,0},{2,-1}},
		 {{0,1},{1,1},{1,2}},
		 {{1,0},{1,1},{2,1}},
		 {{1,-1},{0,1},{0,1}}
};
void find_top_left(int *x,int *y)
{
  int i,j;
  for(i=0;i<HEIGHT;i++)
    for(j=0;j<WIDTH;j++)
      if(heimen[i][j]=='1')
	{*x = j;*y = i;return;}
}
int find_tetoromino(x,y)
{
  int i,j,c;
  int x1,y1;
  char buf[100];

  for(i=0;i<TETOROS;i++)
    {
      c=0;
      for(j=0;j<3;j++)
	{
	  y1 = y+tetoro[i][j][0]; 
	  x1 = x+tetoro[i][j][1];
	  if(x1 < 0 || y1 < 0 || x1 > WIDTH-1 || y1 > HEIGHT-1)
	    break;
	  c += (heimen[y1][x1]=='1')?1:0;
	}
      if(c==3)
	return(i+1);
    }
  return(-1);
}

main()
{
  int i;
  int x,y;
  char dummy[10];
  int ret;
  int ff;

  ff=0;
  do
    {
      if(ff==0)
	for(i=0;i<8;i++)
	  {
	    scanf("%s",&heimen[i][0]);
	    ff=1;
	  }
      else
	for(i=0;i<7;i++)
	  scanf("%s",&heimen[i+1][0]);

      find_top_left(&x,&y);

      ret=find_tetoromino(x,y);

      printf("%c\n",'A'+(ret-1));

    }
  while(EOF != scanf("%s",&heimen[0][0]));
return(0);
}

Measured memory_bytes: 0
/** 以下のような、たてH cm よこ W cm のチェック柄の長方形を描くプログラムを作成して下さい。
#.#.#.#.#.
.#.#.#.#.#
#.#.#.#.#.
.#.#.#.#.#
#.#.#.#.#.
.#.#.#.#.#


上図は、たて 6 cm よこ 10 cm の長方形を表しています。

長方形の左上が "#" となるように描いて下さい。


 */

/*sucannerクラス使うためにインポート*/
import java.util.Scanner;

class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成
		Scanner sc = new Scanner(System.in);
		// 処理を繰り返す
		while (true) {
			// ２つの数字を受け取る
			int intH = sc.nextInt();
			int intW = sc.nextInt();
			// 受け取った数字が二つとも０の場合処理を終了する
			if (intH == 0 && intW == 0) {
				break;
			}
			// 受け取った縦の数字の回数改行処理を繰り返す
			for (int i = 0; i < intH; i++) {
				// 受けとった横の数字の個数分 処理を繰り返す
				for (int j = 0; j < intW; j++) {
					//縦奇数の場合横の奇数列に＃を表示
					//横偶数の場合横の偶数列に＃を表示する
					if ((i+j)%2 == 0) {
						System.out.print("#");
					//上の条件に当てはまらない場合.を表示する
					} else {
						System.out.print(".");
					}
				}
				// 表示完了後改行する。
				System.out.println();
			}
			//改行する。
			System.out.println();
		}
	}
}

Measured memory_bytes: 26784
#include <cmath>
#include <iostream>
typedef long long int ll;
typedef long double ld;

int main(void){
	ll A, res;
	float b;
	std::cin >> A >> b;
	float B = std::round(b * 100);
	res = (A * B) / 100;
	
	std::cout << res << std::endl;
	return 0;
}
// WA, AC with answer


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    string a;
    cin >> a;
    int ans = 700;
    REP(i, a.size()){
        if(a[i] == 'o') ans += 100;
    }
    pr(ans);
}

Measured memory_bytes: 256
# include <iostream>
# include <cmath>
# include <iomanip>
using namespace std;
 
int main() {
  cout << setprecision(20);
  double a, b, h, m; cin >> a >> b >> h >> m;
  double a_angle = 30.0 * (h + m / 60) * M_PI / 180.0;
  double b_angle = 6.0 * m * M_PI / 180.0;
  
  double a_x = sin(a_angle) * a, a_y = cos(a_angle) * a;
  double b_x = sin(b_angle) * b, b_y = cos(b_angle) * b;
  
  double distance = sqrt(pow(a_x - b_x, 2.0) + pow(a_y - b_y, 2.0));
  cout << distance << endl;
  
  return 0;
}

Measured memory_bytes: 4080
#include<iostream>
#include<cmath>
#include<algorithm>
#include <iomanip> 
#include<vector>
#define fo(i,n) for(int i=0;i<n;i++)
#define f(i,n) for(int i=2;i<=n;i++)
#define ll long long
/*Elegizip, elegizip otken sol bir shaktar-ai
 Elendeter zamanymnyn otip bara zhatkanny-ai
Umytylmas-Umytylmas Kairan esil shaktar-ai
Zamanymnyn kolyn bulgap otip bara jatkany-ai
 kairan esil , kairan esil shaktar-ai
kolyn bulgap zamanymnyn otip bara jatkany-ai;*/
using namespace std;

int main()
{ios::sync_with_stdio(0);
string s;
cin>>s;

if(s[2]==s[3] && s[4]==s[5])
cout<<"Yes";
else cout<<"No";


}






Measured memory_bytes: 256
loop{
	n,r = gets.split(nil)
	n = n.to_i()
	r = r.to_i()
	if ((n==0) and (r==0)) then
		break
	end
	
	arr = [*1..n]
	arr.reverse!
	
	for i in 1..r do
		p,c =gets.split.map(&:to_i)
		
		arr2 = arr[p-1..p+c-2]
		if (p == 1) then
			arr3 =[]
		else
			arr3 = arr[0..p-2]
		end
		
		arr = arr2+arr3+arr[p+c-1..n-1]
		
	end
	p arr[0]
}

Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    string s,fro="",bac="";
    int q,now=1;
    cin>>s>>q;
    rep(i,q){
        int t;
        cin>>t;
        if(t==1){
            if(now==1) now--;
            else now++;
        }
        else{
            int f;
            char k;
            cin>>f>>k;
            if(f==1){
                if(now==1){
                    fro=k+fro;
                }
                else{
                    bac=bac+k;
                }
            }
            else{
                if(now==1){
                    bac=bac+k;
                }
                else{
                    fro=k+fro;
                }
            }
        }
    }
    s=fro+s+bac;
    if(now==0) reverse(s.begin(),s.end());
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 4520
package main

import "fmt"

func main() {
	list := []int{
		1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51,
	}
	var k int
	fmt.Scan(&k)
	fmt.Println(list[k-1])
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a1, a2, a3, a4;
  cin >> n;
  
  a1 = n / 1000;
  a2 = (n % 1000) / 100;
  a3 = (n % 100) / 10;
  a4 = n % 10;

  if ((a1 == a2) && (a2 == a3)) {
    cout << "Yes" << endl;
  }
  else if ((a2 == a3) && (a3 == a4)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

int main(){
    std::ios_base::sync_with_stdio(false);
    
    int h,w; cin >> h >> w;
    bool cells[2000][2000];
    rep(i,2000) rep(j,2000) cells[i][j] = false;

    rep(i,h){
        string s; cin >> s;
        rep(j,w){
            if(s[j]=='.') cells[i][j] = true;
        } 
    }
    
    int shita[2000][2000]; rep(i,2000) rep(j,2000) shita[i][j] = 0;
    int ue[2000][2000]; rep(i,2000) rep(j,2000) ue[i][j] = 0;
    int migi[2000][2000]; rep(i,2000) rep(j,2000) migi[i][j] = 0;
    int hidari[2000][2000]; rep(i,2000) rep(j,2000) hidari[i][j] = 0;

    rep(j,w){
        int cur = 0;
        rep(i,h){
            shita[i][j] = cur;
            if(cells[i][j]) cur+=1;
            else cur=0;
        }
    }

    rep(j,w){
        int cur = 0;
        rep(i,h){
            ue[h-i-1][w-j-1] = cur;
            if(cells[h-i-1][w-j-1]) cur+=1;
            else cur=0;
        }
    }

    rep(i,h){
        int cur = 0;
        rep(j,w){
            migi[i][j] = cur;
            if(cells[i][j]) cur+=1;
            else cur=0;
        }
    } 

    rep(i,h){
        int cur = 0;
        rep(j,w){
            hidari[h-i-1][w-j-1] = cur;
            if(cells[h-i-1][w-j-1]) cur+=1;
            else cur=0;
        }
    }   

    int m = 0;
    rep(i,h){
        rep(j,w){
            if(cells[i][j]) m = max(m, shita[i][j]+ue[i][j]+migi[i][j]+hidari[i][j]+1);
        }
    }

    cout << m << endl;

    
    return 0;
}

Measured memory_bytes: 66688
# -*- coding: utf-8

while True:
   A = raw_input().split()
   if A[1] == '?':
      break
   if A[1] == '+':
      print(int(A[0])+int(A[2]))
   if A[1] == '-':
      print(int(A[0])-int(A[2]))
   if A[1] == '*':
      print(int(A[0])*int(A[2]))
   if A[1] == '/':
      print(int(A[0])/int(A[2]))





Measured memory_bytes: 4664
#!/usr/bin/env python3
_, c, k, *t = map(int, open(0).read().split())
t.sort()
n = 0
f = t.pop(0)
p = 1
for i in t:
    if i > f + k or p >= c:
        n += 1
        p = 1
        f = i
    else:
        p += 1
print(n + 1)


Measured memory_bytes: 20004
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){

  map <ll,ll> m;
  ll N;cin>>N;
  vector<ll> a(N);
  rep(i,N-1) cin>>a[i];
  rep(i,N-1){
    m[a[i]]++;
  }

  repn(i,N-1){
    cout<<m[i]<<endl;
  }
  cout<<0<<endl;
}


Measured memory_bytes: 17224
#!/usr/bin/env python3
#AGC6 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,x = LI()
if x == 1 or x == 2*n-1:
    print('No')
elif x - 1 == 1:
    print('Yes')
    if n == 2:
        print(1,2,3)
        quit()
    ans = [0]*(2*n-1)
    ans[(2*n-1)//2] = x
    ans[(2*n-1)//2-1] = x+2
    ans[(2*n-1)//2+1] = x-1
    tmp = 1
    for i in range(2*n-1):
        if tmp == x-1:
            tmp = x+1
        if tmp == x+2:
            tmp += 1
        if ans[i] == 0:
            ans[i] = tmp
            tmp += 1
    print(*ans)
else:
    print('Yes')
    ans = [0]*(2*n-1)
    ans[(2*n-1)//2] = x
    ans[(2*n-1)//2+1] = x+1
    ans[(2*n-1)//2-1] = x-2
    tmp = 1
    for i in range(2*n-1):
        if tmp == x-2:
            tmp = x-1
        elif tmp == x:
            tmp = x+2
        if ans[i] == 0:
            ans[i] = tmp
            tmp += 1
    print(*ans)


Measured memory_bytes: 50356
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return b.second > a.second;
    }
    return a.first < b.first;
}

int arr[200010];
int a[200010], b[200010];

int GCD(int a, int b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    return GCD(b, a % b);
}

int dp[55][30][30][30];

int rec(int sum, int cost, int a, int b, int c)
{
    if (sum == 0)
    {
        return cost;
    }
    if (sum < 0)
    {
        return INT_MAX;
    }
    if (dp[sum][a][b][c] != INT_MAX)
        return dp[sum][a][b][c];

    int res = INT_MAX;

    if ((a + 1) % 5 == 0)
    {
        res = min(res, rec(sum - 2, cost - 380 * 4 + 380 * 5 * 0.80, a + 1, b, c));
    }
    else
    {
        res = min(res, rec(sum - 2, cost + 380, a + 1, b, c));
    }

    if ((b + 1) % 4 == 0)
    {
        res = min(res, rec(sum - 3, cost - 550 * 3 + 550 * 4 * 0.85, a, b + 1, c));
    }
    else
    {
        res = min(res, rec(sum - 3, cost + 550, a, b + 1, c));
    }

    if ((c + 1) % 3 == 0)
    {
        res = min(res, rec(sum - 5, cost - 850 * 2 + 850 * 3 * 0.88, a, b, c + 1));
    }
    else
    {
        res = min(res, rec(sum - 5, cost + 850, a, b, c + 1));
    }

    return dp[sum][a][b][c] = min(dp[sum][a][b][c], res);
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    int n;
    while (cin >> n)
    {
        if (n == 0)
        {
            break;
        }

        for (int i = 0; i < 55; ++i)
        {
            for (int j = 0; j < 30; ++j)
            {
                for (int k = 0; k < 30; ++k)
                {
                    for (int l = 0; l < 30; ++l)
                    {
                        dp[i][j][k][l] = INT_MAX;
                    }
                }
            }
        }
        n /= 100;
        cout << rec(n, 0, 0, 0, 0) << endl;
    }
    return 0;
}


Measured memory_bytes: 8896
#include <stdio.h>
int main(){
	int s, a, b, c, d;
	scanf("%d", &s);
	
	a = s % 10;
	b = s / 10 % 10;
	c = s / 100 % 10;
	d = s / 1000;
	
	if(a == b || b == c || c == d){
		printf("Bad");
	}else{
		printf("Good");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize(-O3)
#pragma GCC optimize(0fast)
#pragma GCC optimize("unroll-loops")

#define fi first
#define se second
#define sqr(x) (x) * (x)
#define p_b push_back
#define m_p make_pair
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define pw(x) (1ll << x)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 1e6;
const ll MOD = 1e9 + 7;

template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T> void vout(T s){cout << s << endl; exit(0);}


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

    ll n;

    cin >> n;

    vector <pll> a(n);

    for(int i = 0; i < n; i++)cin >> a[i].se >> a[i].fi;
    sort(all(a));

    ll t = 0, ans = 0;

    for(int i = 0; i < n; i++){
        if(t + a[i].se <= a[i].fi){
            ans++;
            t += a[i].se;
        }
    }

    if(n == ans)vout("Yes");
    vout("No");

    return 0;
}


Measured memory_bytes: 3456
#include <cstdio>
using namespace std;

#define INF 101

int M,N;

int f[100][100];
int p[50][50][4];

void check(int x, int y, int d, int& ansx, int& ansy)
{
	int mx=INF, my=INF;
	for(int i=0; i<N; i++)
	for(int j=0; j<N; j++)
	{
		if(p[j][i][d]==-1) continue;
		if(p[j][i][d]!=f[j+x][i+y]) return;
		
		if(my>(i+y) || (my==(i+y)&&mx>(j+x)) )
		{
			mx=j+x;
			my=i+y;
		}
	}
	
	if(ansy>my || (ansy==my&&ansx>mx) )
	{
		ansx=mx;
		ansy=my;
	}
}

int main()
{
	while(scanf("%d%d", &M,&N), (N||M))
	{
		for(int i=0; i<M; i++)
		for(int j=0; j<M; j++)
			scanf("%d", &f[j][i]);
			
		for(int i=0; i<N; i++)
		for(int j=0; j<N; j++)
			scanf("%d", &p[j][i][0]);
			
		for(int i=0; i<3; i++)
		for(int j=0; j<N; j++)
		for(int k=0; k<N; k++)
			p[N-1-j][k][i+1]=p[k][j][i];
			
		int ansx=INF, ansy=INF;
		for(int j=0; j<=(M-N); j++)
		for(int k=0; k<=(M-N); k++)	
		for(int i=0; i<4; i++)
			check(k,j,i,ansx,ansy);
			
		if(ansx==INF) puts("NA");
		else printf("%d %d\n", ansx+1,ansy+1);
	}
			
}

Measured memory_bytes: 820
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

class UnionFind {
  std::vector<intmax_t> tree;

public:
  UnionFind(size_t n): tree(n, -1) {}

  size_t find(size_t v) {
    if (tree[v] < 0)
      return v;

    return (tree[v] = find(tree[v]));
  }

  bool unite(size_t u, size_t v) {
    u = find(u);
    v = find(v);
    if (u == v)
      return false;

    if (-tree[u] >= -tree[v])
      std::swap(u, v);

    tree[v] += tree[u];
    tree[u] = v;
    return true;
  }

  bool connected(size_t u, size_t v) {
    return (find(u) == find(v));
  }

  size_t size(size_t v) {
    return -tree[find(v)];
  }
};

template <class RandomIt>
auto rsort(RandomIt first, RandomIt last)
  -> typename std::enable_if<std::is_integral<
    typename RandomIt::value_type::first_type>::value>::type
{
  using PairType = typename RandomIt::value_type;
  using KeyType = typename PairType::first_type;

  intmax_t cur_shift=0, max_exp=sizeof(KeyType);
  std::vector<PairType> work(last-first);
  for (int i=0; i<max_exp; ++i) {
    size_t num[256]={};

    for (RandomIt it=first; it<last; ++it)
      ++num[((it->first)>>cur_shift)&255];

    {
      size_t tmp=0;
      for (int j=0; j<256; ++j)
        std::swap(tmp, num[j]+=tmp);
    }

    for (RandomIt it=first; it<last; ++it)
      work[num[((it->first)>>cur_shift)&255]++] = *it;

    {
      size_t j=0;
      for (RandomIt it=first; it<last; ++it)
        *it = work[j++];
    }

    cur_shift += 8;
  }

  if (!std::is_signed<KeyType>::value) return;

  RandomIt mid=last;
  for (RandomIt it=last; --it>=first;)
    if ((it->first) >= 0) {
      mid = ++it;
      break;
    }

  if (mid == last)
    return;

  std::copy(first, mid, work.begin()+(last-mid));
  std::copy(mid, last, work.begin());
  std::copy(work.begin(), work.end(), first);
}

int main() {
  size_t W, H;
  scanf("%zu %zu", &W, &H);

  std::vector<std::pair<unsigned, size_t>> es;
  for (size_t j=0; j<W; ++j) {
    unsigned p;
    scanf("%u", &p);
    es.emplace_back(p, j);
  }

  for (size_t i=0; i<H; ++i) {
    unsigned q;
    scanf("%u", &q);
    es.emplace_back(q, W+i);
  }

  rsort(es.begin(), es.end());
  size_t a=W+1, b=H+1;
  uintmax_t res=0;
  UnionFind uf(a+b);
  for (const auto &e: es) {
    if (uf.connected(e.second, e.second+1))
      continue;

    uf.unite(e.second, e.second+1);
    if (e.second < W) {
      res += e.first*b;
      --a;
    } else {
      res += e.first*a;
      --b;
    }
  }

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


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

int n;cin >> n;
string s;cin >> s;

for(int i=0;i<s.length();i++){
    int x = s.at(i)-'A';
    x=(x+n)%26;
    cout << (char)(x+'A');
}
cout << endl;

return 0;

}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"os"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func cipher(text string, direction int, int_shift int) string {
	shift, offset := rune(int_shift), rune(26)
	runes := []rune(text)
	for index, char := range runes {
		switch direction {
		case 1:
			if char >= 'a' && char <= 'z'-shift || char >= 'A' && char <= 'Z'-shift {
				char = char + shift
			} else if char > 'z'-shift && char <= 'z' || char > 'Z'-shift && char <= 'Z' {
				char = char + shift - offset
			}
		case -1:
			if char >= 'a'+shift && char <= 'z' || char >= 'A'+shift && char <= 'Z' {
				char = char - shift
			} else if char >= 'a' && char < 'a'+shift || char >= 'A' && char < 'A'+shift {
				char = char - shift + offset
			}
		}
		runes[index] = char
	}
	return string(runes)
}

func main() {
	for scanner.Scan() {
		infos := strings.Split(scanner.Text(), " ")
		plain := make([]string, len(infos))
		// fmt.Println(infos)
		Decryption:
			for i := 0; i < 26; i++ {
				for j := range infos {
					plain[j] = cipher(infos[j], 1, i)
				}
				for j := range plain {
					if plain[j] == "this" || plain[j] == "that" || plain[j] == "the" {
						break Decryption
					}
				}
			}
			fmt.Println(strings.Join(plain, " "))
	}
}



Measured memory_bytes: 1092
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>
#include<chrono>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 3e5 + 5;

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    ll n; cin >> n;
    vector<ll>a(n);
    ll mx = 0;
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        ans += max(0LL, mx - a[i]);
        mx = max(mx, a[i]);
    }
    cout << ans << endl;
    return 0;
}

/*


*/

/*

*/

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

using namespace std;

#define fto(i, s, e) for(int i = s; i <= e; ++i)
#define fto1(i, s, e) for(int i = s; i < e; ++i)
#define fdto(i, s, e) for(int i = s; i >= e; --i)
#define fit(var, it) for(__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define frit(var, it) for(__typeof(var.rbegin()) it = var.rbegin(); it != var.rend(); ++it)

#define newl '\n'
#define debugt cerr << 0.001*clock() << newl
#define debug1(x, i) cout << #x << '[' << i << "] = " << x[i] << newl
#define debug(v, l, r) fto(_i, l, r) debug1(v, _i)
#define debug2(x, i, j) cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << newl
#define debug3(x, i, j, k) cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] << newl

#define ll long long
#define ii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define glen(v) int((v).size())

template<typename T1, typename T2> ostream& operator<< (ostream &os, pair<T1, T2> const &v) {
	return os << '(' << v.ff << ", " << v.ss << ')';
}

#define eps 1e-15
#define oo 1000000007
#define OO 1000000000000000003LL
#define maxn 103

int n, k;
int a[maxn], sum[100003];
int f[maxn][100003];

int main() {
	//ios_base::sync_with_stdio(0); cin.tie(0);

	scanf("%d%d", &n, &k);

	fto (i, 1, n) scanf("%d", &a[i]);

	fto (i, 0, k) sum[i] = 1;

	fto (i, 1, n) {
		fto (j, 0, k) {
			int mn = min(j, a[i]);
			f[i][j] = (sum[j] - (j-mn == 0 ? 0 : sum[j-mn-1])) % oo;
			if (f[i][j] < 0) f[i][j] += oo;
		}
		sum[0] = f[i][0];
		fto (j, 1, k) sum[j] = (sum[j-1] + f[i][j]) % oo;
	}

	printf("%d\n", f[n][k]);

	return 0;
}


Measured memory_bytes: 39680
#include  <iostream>
#include  <vector>
#include  <string>
#include  <algorithm>
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; }
#define rep(i, n) for(int i = 0; i < n; i++)

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

const int INF = 1 << 29;
const ll LINF = 1LL << 60;
const int R = 1e9 + 7;

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

	vector<vector<vector<ll> > > dp(n + 1, vector<vector<ll>>(a * n + 1, vector<ll>(n + 1, 0)));  //初期化
	dp[0][0][0] = 1; //初期条件
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= a * n; j++) {
			for (int k = 0; k <= n; k++) {
				if (j >= x[i] && k - 1 >= 0)   dp[i + 1][j][k] += dp[i][j - x[i]][k - 1];
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}
	ll ans = 0;
	rep(i, n) {
		int v = a * (i + 1);
		ans += dp[n][v][i + 1];
	}
	cout << ans << endl;
}

Measured memory_bytes: 56192
#include<bits/stdc++.h>
using namespace std;
int main(){
double sum,y1=1,y2=0;
int n,a[105];
cin>>n;
for(int i=0;i<n;i++){
	cin>>a[i];
	//y3+=a[i];
	y1*=a[i];	
}
  for(int i=0;i<n;i++){
		y2+=y1/a[i];	
}
sum=y1/y2;
printf("%.6f",sum);
return 0;
}

Measured memory_bytes: 384
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t  i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

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

  ll a,b,c;
  std::cin>>a>>b>>c;

  if(c-a-b<=0){
    std::cout<<"No\n";
    return 0;
  }

  if(a*a+b*b+c*c-2*a*b-2*b*c-2*c*a>0){
    std::cout<<"Yes\n";
  }else{
    std::cout<<"No\n";
  }

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    // 入力受け取り, 入次数も管理する
int n;
    cin >> n;
int data[n];

for(int i=0;i<n;i++){
cin >> data[i];
}
int sum=0;

for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
sum+=data[i-1]*data[j-1];
}
}

cout <<sum;




}




Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N=2010;

int n;
pair<ll,ll> a[N];
ll f[N][N];
//f[i][j]表示前j-i+1个数选[i,j] 

int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		ll x; scanf("%lld",&x);
		a[i]=mk(x,i);
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++) f[i][i]=a[1].first*abs(a[1].second-i);
	for(int k=2;k<=n;k++) {
		int x=a[k].first,y=a[k].second;
		for(int i=1,j=k;j<=n;i++,j++) 
			f[i][j]=max(f[i][j-1]+x*llabs(y-j),f[i+1][j]+x*llabs(y-i));
	}
	printf("%lld\n",f[1][n]); return 0;
}
	

Measured memory_bytes: 24420
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll s1, s2, c1, c2;
int main() {
	ll n, a;
	scanf("%lld", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a);
		s1 += a;
		s2 += a;
		if (i % 2) {
			if (s1 <= 0) c1 += 1 - s1,s1 = 1;
			if (s2 >= 0) c2 += 1 + s2,s2 = -1;
		}
		else {
			if (s1 >= 0) c1 += 1 + s1,s1 = -1;
			if (s2 <= 0) c2 += 1 - s2,s2 = 1;
		}
	}
	cout << min(c1, c2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	double x[4], y[4], xp, yp;
	double vx, vy, vpx, vpy;
	double crossZ;
	while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &xp, &yp) != EOF)
	{
		bool ans = true;
		bool prev, sign;
		x[3] = x[0]; y[3] = y[0];
		for(int i = 0; i < 3; i++)
		{
			vx = x[i+1] - x[i];
			vy = y[i+1] - y[i];
			vpx = xp - x[i];
			vpy = yp - y[i];
			//printf("%d: vx=%lf vy=%lf vpx=%lf vpy=%lf\n\n",i,vx,vy,vpx,vpy);
			crossZ = vx * vpy - vy * vpx;
			sign = crossZ>0?true:false;
			//printf("cross = %lf\n", crossZ);
			if(i == 0)
			{
				prev = sign;
			}
			else
			{
				if(prev != sign)
				{
					ans = false;
					break;
				}
			}
		}
		cout << (ans?"YES":"NO") << endl;
	}
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back

using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }

int n, m, sx, sy, ex, ey, bel[1100][1100], cnt, v[1000100];
const int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
char s[1100][1100]; set<int> G[1000100];
bool valid(int x, int y) {
	return 1 <= x && x <= n && 1 <= y && y <= m && s[x][y] == '.';
}
signed main() {
	scanf("%d %d", &n, &m);
	scanf("%d %d", &sx, &sy);
	scanf("%d %d", &ex, &ey);
	for(int i = 1; i <= n; i++)
		scanf("%s", s[i] + 1);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++) if(!bel[i][j] && s[i][j] == '.') {
			queue<pii> q; q.push(Mp(i, j)); bel[i][j] = ++cnt;
			while(q.size()) {
				pii x = q.front(); q.pop();
				for(int i = 0; i < 4; i++) {
					pii y = Mp(x.fi + dx[i], x.se + dy[i]);
					if(!valid(y.fi, y.se) || bel[y.fi][y.se]) continue;
					bel[y.fi][y.se] = cnt, q.push(y);
				}
			}
		}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			if(s[i][j] == '.')
				for(int x = -2; x <= 2; x++)
					for(int y = -2; y <= 2; y++) {
						int i_ = i + x, j_ = j + y;
						if(!valid(i_, j_) || bel[i_][j_] == bel[i][j]) continue;
						int nw = bel[i][j], to = bel[i_][j_];
						G[nw].insert(to), G[to].insert(nw);
					}
	int st = bel[sx][sy], ed = bel[ex][ey];
	queue<pii> q; q.push(Mp(st, 0)); v[st] = 1;
	while(q.size()) {
		pii x = q.front(); q.pop();
		if(x.fi == ed) return printf("%d\n", x.se), 0;
		for(int y : G[x.fi]) if(!v[y]) q.push(Mp(y, x.se + 1)), v[y] = 1;
	}
	puts("-1");
	// fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
	return 0;
	/* 取模直接除，爆零两行泪
	 * 不开ll见祖宗
	 */
}

Measured memory_bytes: 75052
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  ll n;cin>>n;
  string ans="";
  ll num;
  while(n>0){
  num=n%26;
  if(num==0)num=26;
  n-=num;
  n/=26;
  ans=(char)('a'+num-1)+ans;
  
  }
  cout<<ans;
}

Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
N,Q=map(int,input().split())
ans=[0]*N
ki=[[] for _ in range(N)]
for i in range(N-1):
 a,b=map(int,input().split())
 ki[a-1].append(b-1)
 ki[b-1].append(a-1)
for i in range(Q):
 p,q=map(int,input().split())
 ans[p-1]+=q
# dfs
from collections import deque
stack =deque([0])
visited = ["False"] * N
while stack:
 ne = stack.popleft()
 if visited[ne] == "False":
  visited[ne] = "True"
  for j in ki[ne]:
   if visited[j] == "False":
    ans[j]+=ans[ne]
    stack.append(j)
print(*ans)


Measured memory_bytes: 56152
/*
....................
....................
*/
#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;


int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    ll n=s.size(),m=t.size();
    ll dp[n+1][m+1],i,j,k;
    for(i=0;i<n+1;i++)
    {
    	dp[i][0]=0;
    }
    for(i=0;i<m+1;i++)
    {
    	dp[0][i]=0;
    }
    for(i=1;i<n+1;i++)
    {
    	for(j=1;j<m+1;j++)
    	{
    		if(s[i-1]==t[j-1])
    		{
    			dp[i][j] = 1 + dp[i-1][j-1];
    		}
    		else
    		{
    			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
    		}
    	}
    }
    i=n,j=m;
    string ans="";
    // cout<<dp[n][m]<<endl;
    while(i>0&&j>0)
    {
    	if(s[i-1]==t[j-1])
    	{
    		ans+=s[i-1];
    		i--;j--;
    	}
    	else if(dp[i-1][j]>dp[i][j-1])
    	{
    		i--;
    	}
    	else
    		j--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string n;
  cin >> n;
  rep(i, n.length()) {
    if (n[i] == '1')
      n[i] = '9';
    else
      n[i] = '1';
  }
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<double, double> p;
constexpr double DISTANCE = 1e11;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<p> holes(N);
    double ax = 0.0, ay = 0.0;
    for (auto&& h : holes) {
        double x, y;
        cin >> x >> y;
        h = p(x, y);
        ax += x;
        ay += y;
    }

    ax /= holes.size();
    ay /= holes.size();

    for (auto&& h : holes) {
        h = p(h.first - ax, h.second - ay);
    }

    vector<ll> cupin(N, 0);
    ll cnt = 0;
    double delta = M_PI / 1800000.0;
    for (double theta = 0; theta < 2 * M_PI; theta += delta) {
        double mini = 1e100;
        double idx = -1;
        
        double px = DISTANCE * cos(theta);
        double py = DISTANCE * sin(theta);

        for (ll i = 0; i < N; i++) {
            double hx = holes[i].first;
            double hy = holes[i].second;
            double dx = px - hx;
            double dy = py - hy;
            double d = sqrt(dx * dx + dy * dy);
            if (d < mini) {
                mini = d;
                idx = i;
            }
        }

        cupin[idx]++;
        cnt++;
    }

    for (auto c : cupin) {
        printf("%.15f\n", (double)c / (double)cnt);
    }

    /*
    cout << ax << "," << ay << endl;

    vector<double> D;
    for (auto&& h : holes) {
        double dx = h.first - ax;
        double dy = h.second - ay;
        cout << h.first << "," << h.second << endl;
        cout << sqrt(dx * dx + dy * dy) << endl;
        D.push_back(sqrt(dx * dx + dy * dy));
    }

    double dsum = 0.0;
    for (auto&& d : D) {
        dsum += d;
    }
    
    for (auto&& d : D) {
        printf("%.11f\n", d / dsum);
    }
    */
}



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

int main()
{
  int n,k;
  cin>>n>>k;
  vector<string> v(n);
  for(auto &i:v) cin>>i;
  sort(v.begin(),v.end());
  for(auto i:v) cout<<i;
  cout<<"\n";
  return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : AOJ1180.cpp
// Author      : mizo0203
// Version     :
// Copyright   : Your copyright free
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <functional>
using namespace std;

int a0, L;

bool input() {
  scanf("%d %d", &a0, &L);
  if (!a0 && !L)
    return false;
  return true;
}

int main() {
  int i, j;
  char a[21][7];
  char b[2][7];

  while (input()) {
    sprintf(a[0], "%0*d", L, a0);
    //printf("%s\n", a[0]);

    for (i = 1;; i++) {
      strcpy(b[0], a[i - 1]);
      strcpy(b[1], a[i - 1]);
      sort(b[0], b[0] + L);
      sort(b[1], b[1] + L, greater<int>());
      sprintf(a[i], "%0*d", L, atoi(b[1]) - atoi(b[0]));
      //printf("%s=%s-%s\n", a[i], b[1], b[0]);

      for (j = 0; j < i; j++) {
        if (!strcmp(a[j], a[i])) {
          printf("%d %d %d\n", j, atoi(a[j]), i - j);
          break;
        }
      }
      if (j != i)
        break;

    }
  }

  return 0;
}

Measured memory_bytes: 1092
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MOD = 1e9+7;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//C++17以上
template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

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

    sort(ALL(d));
    int ans = 0;
    int target = n/2;
    for(int i=0;i<=d[n-1];i++){
        auto Iter = lower_bound(ALL(d),i);
        if(target == (Iter - d.begin()) && target == (d.end() - Iter))
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640