akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
void chmin(int &a, int b) {if(a > b) a = b;}
void chmax(int &a, int b) {if(a < b) a = b;}

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};


int main(){
    int n;
    cin >> n;
    int keta = 1000;
    vi a(4);
    rep(i,0,4){
        a[i] = n/keta;
        n -= a[i]*keta;
        keta/=10;
    }
    vi op(3);
    for(int i = 0 ; i < (1<<3) ; i++) {
        int ans = a[0];
        vi p(3);
        for(int bit = 0 ; bit < 3 ; bit++){
            if(1&(i>>bit)){
                ans += a[bit+1];
                p[bit] = 1;
            }else{
                ans -= a[bit+1];
                p[bit] = 0;
            }
        }
        if(ans == 7){
            op = p;
            break;
        }
    }
    for(int i = 0 ; i < 4 ; i++){
        if(i == 3) cout << a[i] << "=7"<< endl;
        else if(op[i] == 1)cout << a[i] << '+';
        else cout << a[i] << '-';
    }
}

Measured memory_bytes: 256
# Problem C - Energy Drink Collector

# input
N, M = map(int, input().split())
ab_list = []
for i in range(N):
    a, b = map(int, input().split())
    ab_list.append([a, b])

# initialization
ab_list = sorted(ab_list, key=lambda x: x[0])
min_cost = 0

# count
i = 0
nokori = M
while nokori>0:
    a, b = ab_list[i]

    if nokori-b<0:
        b = nokori
        nokori = 0
    else:
        nokori -= b

    min_cost += a * b
    i += 1

# output
print(min_cost)


Measured memory_bytes: 63400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int X,Y,Z,K; cin >> X >> Y >> Z >> K;
    vector<ll> a(X), b(Y), c(Z);
    for(int i=0; i<X; i++) cin >> a[i];
    for(int i=0; i<Y; i++) cin >> b[i];
    for(int i=0; i<Z; i++) cin >> c[i];

    vector<ll> ab;
    for(int i=0; i<X; i++) for(int j=0; j<Y; j++) ab.push_back(a[i]+b[j]);

    vector<ll> abc;
    sort(ab.begin(), ab.end(), greater<ll>());
    for(int i=0; i<min((int)ab.size(), K); i++) for(int j=0; j<Z; j++){
        abc.push_back(ab[i]+c[j]);
    }

    sort(abc.begin(), abc.end(), greater<ll>());
    for(int i=0; i<K; i++) cout << abc[i] << endl;

}

Measured memory_bytes: 43368
sx,sy,tx,ty = map(int,input().split())
route = ''
x_diff = tx - sx
y_diff = ty - sy

#行き1の経路:y軸から移動,x軸最後に移動
for i in range(y_diff):
    route += 'U'
for i in range(x_diff):
    route += 'R'

#帰り1の経路:y軸降りる,x軸左に
for i in range(y_diff):
    route += 'D'
for i in range(x_diff):
    route += 'L'

#行き2の経路:左に1ずれ,上にy_diff+1移動した後x_diff+1移動し1降りる
route += 'L'
for i in range(y_diff+1):
    route += 'U'
for i in range(x_diff+1):
    route += 'R'
route += 'D'

#帰り2の経路:右1ずれ,下y_diff+1移動,x_diff+1左移動し1上に
route += 'R'
for i in range(y_diff+1):
    route += 'D'
for i in range(x_diff+1):
    route += 'L'
route += 'U'
print(route)

Measured memory_bytes: 3064
import std.format;
import std.stdio;
import std.string;


void main() {
  int a,b,c;
  string s = readln.strip;
  formattedRead(s, " %s %s %s", &a, &b, &c);

  int ans = 3;
  if (a == b && b == c)
    ans = 1;
  else if (a == b || b == c || c == a)
    ans = 2;

  writeln(ans);
}


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

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

    int N;
    cin >> N;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
        reverse(S[i].begin(), S[i].end());
    }
    sort(S.begin(), S.end(), [](auto& s1, auto& s2) {
        return s1.size() < s2.size();
    });
    unordered_map<ll, int> mp;
    const ll base = 100007;
    ll ans = 0;
    for (auto& s : S) {
        int n = s.size();
        vector<ll> hashes(n);
        hashes[0] = s[0];
        for (int i = 1; i < n; i++) hashes[i] = hashes[i-1] * base + s[i];
        vector<int> cnt(26);
        for (int i = 0; i < n; i++) cnt[s[i] - 'a']++;
        for (int c = 0; c < 26; c++) {
            if (cnt[c] == 0) continue;
            ll h = c + 'a';
            if (mp.count(h)) ans += mp[h];
        }
        for (int i = 0; i < n - 1; i++) {
            ll h = hashes[i] * base;
            cnt[s[i] - 'a']--;
            for (int c = 0; c < 26; c++) {
                if (cnt[c] == 0) continue;
                h += c + 'a';
                if (mp.count(h)) ans += mp[h];
                h -= c + 'a';
            }
        }
        if (mp.count(hashes[n-1]) == 0) mp[hashes[n-1]] = 1;
        else mp[hashes[n-1]]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 17632
#include <iostream>
using namespace std;
int main(void){
    long long n,w,d[102][100002],INF=1e18;
    cin>>n>>w;
    d[0][0]=0;
    for(int i=1;i<=100000;i++){
        d[0][i]=INF;
    }
    
    for(int i=1;i<=n;i++){
        int q,v;
        cin>>q>>v;
        for(int j=0;j<=100000;j++){
            if(j-v<0){
                d[i][j]=d[i-1][j];
            }else{
                d[i][j]=min(d[i-1][j],d[i-1][j-v]+q);
            }
        }
    }
    
    for(int i=100000;i>=0;i--){
        if(d[n][i]<=w){
            cout<<i<<endl;
            return 0;
        }
    }
    
}



Measured memory_bytes: 79488
//nvidia-store@rptechindia.com

#include <iostream>
#include <vector>
#include <algorithm>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
using namespace std;

const int MOD=1e9+7;
const int N=1e3+7;

int H,W;
char arr[N][N];
int dp[N][N];

int solve()
{
	dp[1][1] = 1;
	for (int i = 1; i <= H ; ++i)
	{
		for (int j = 1; j <= W; ++j)
		{
			if (i==1 && j == 1)
				continue;
			if(arr[i][j] == '.')
				dp[i][j] = (dp[i-1][j] + dp[i][j-1] )%MOD;
		}
	}
	return dp[H][W];
}



int32_t main()
{
	IOS;
	cin >> H >> W;
	for (int i = 1; i <= H; ++i)
	{
		for (int j = 1; j <= W; ++j)
		{
			cin >> arr[i][j];
		}
	}
	cout << solve();
	return 0;
}



Measured memory_bytes: 9216
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int point = Integer.parseInt(sc.next());
        int jigen = Integer.parseInt(sc.next());
        List<List<Integer>> pointList = new ArrayList();
        for (int x=1; x<=point; x++) {
            List<Integer> list = new ArrayList();
            for (int y=1; y<=jigen; y++) {
                list.add(Integer.parseInt(sc.next()));
            }
            pointList.add(list);
        }
        int res = 0;
        for(int x=1;x<=point;x++) {
            List<Integer> compareList = pointList.get(x-1);
            for (int y=1;y<=point;y++) {
                if (x==y) {
                    continue;
                }
                List<Integer> list = pointList.get(y-1);
                int r = 0;
                for (int z=1;z<=jigen;z++) {
                    int tmp1 = compareList.get(z-1);
                    int tmp2 = list.get(z-1);
                    r += (int)Math.pow(tmp1-tmp2,2);
                }
                double tmp = Math.sqrt(r);
                double a = (int) tmp;
                if (a*a ==tmp*tmp) {
                    res++;
                }
                
            }
        }
        System.out.println(res/2);
    }
}


Measured memory_bytes: 21844
nyu = input()
nyu = nyu.split()

k = int(nyu[0])
s = int(nyu[1])

n = 0
for x in range(k+1):
  for y in range(k+1):
    if x+y > s or s - (x+y) > k:
      #print(str(x) + " " + str(y))
      continue;
    else:
      n +=1;

print(n)

Measured memory_bytes: 3060
/*
Author : Devil088
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define sep cout<<"\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";

inline string shift(string s){
	int n = s.length();
	string r = "";
	r+=s[n-1];
	for(int i=0;i<n-1;i++)r+=s[i];
	return r;
}

int main(){
	string s,t;
	cin>>s;
	cin>>t;
	bool flag = false;
	int n = s.length();
	while(n--){
		s = shift(s);
		if(s == t){
			flag = true;
			break;
		}
	}
	
	if(flag)Yes
	else No
}
/*
uday
adyu
*/


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n,x;
  scanf("%d%d",&n,&x);
  int l[n];
  for(int i=0;i<n;i++){
scanf("%d",&l[i]);
  }
  int d[n+1],count=1;
  d[0]=0;
  for(int i=1;i<n+1;i++){
d[i]=d[i-1]+l[i-1];
    if(d[i]<=x)count++;
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int a,b;
    cin>>a>>b;
    cout<<max(0,a-b-b)<<endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
string s[8];
int ng[8][8];
bool flg;
void dfs(int r){
    if(r==8){
        flg=1;
        return;
    }
    for(int c=0;c<8;c++){
        if(s[r][c]=='Q'){
            dfs(r+1);
            return;
        }
    }
    for(int c=0;c<8;c++){
        if(ng[r][c])continue;
        s[r][c]='Q';
        for(int j=0;j<8;j++){
            if(r+j<8)ng[r+j][c]++;
            if(r-j>=0)ng[r-j][c]++;
            if(c+j<8)ng[r][c+j]++;
            if(c-j>=0)ng[r][c-j]++;
            if(r+j<8&&c+j<8)ng[r+j][c+j]++;
            if(r+j<8&&c-j>=0)ng[r+j][c-j]++;
            if(r-j>=0&&c+j<8)ng[r-j][c+j]++;
            if(r-j>=0&&c-j>=0)ng[r-j][c-j]++;
        }
        dfs(r+1);
        if(flg)return;
        s[r][c]='.';
        for(int j=0;j<8;j++){
            if(r+j<8)ng[r+j][c]--;
            if(r-j>=0)ng[r-j][c]--;
            if(c+j<8)ng[r][c+j]--;
            if(c-j>=0)ng[r][c-j]--;
            if(r+j<8&&c+j<8)ng[r+j][c+j]--;
            if(r+j<8&&c-j>=0)ng[r+j][c-j]--;
            if(r-j>=0&&c+j<8)ng[r-j][c+j]--;
            if(r-j>=0&&c-j>=0)ng[r-j][c-j]--;
        }
    }
}
int main(){
    rep(i,8)s[i]=string(8,'.');
    int n;cin>>n;
    memset(ng,0,sizeof(ng));
    for(int i=0;i<n;i++){
        int r,c;cin>>r>>c;
        s[r][c]='Q';
        for(int j=0;j<8;j++){
            if(r+j<8)ng[r+j][c]++;
            if(r-j>=0)ng[r-j][c]++;
            if(c+j<8)ng[r][c+j]++;
            if(c-j>=0)ng[r][c-j]++;
            if(r+j<8&&c+j<8)ng[r+j][c+j]++;
            if(r+j<8&&c-j>=0)ng[r+j][c-j]++;
            if(r-j>=0&&c+j<8)ng[r-j][c+j]++;
            if(r-j>=0&&c-j>=0)ng[r-j][c-j]++;
        }
    }
    flg=0;
    dfs(0);
    rep(i,8)cout<<s[i]<<endl;
    return 0;
}


Measured memory_bytes: 3148
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,m,k,ans=1,d[100010],i,j,c,min,a;
  scanf("%d %d %d",&n,&m,&k);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    hin(a);
  }
  for(i=0;i<n;i++)d[i]=N[hout()];
  c=1;
  min=d[0];
  for(i=1;i<n;i++){//printf("%d\n",min);
    c++;
    if(c>m||d[i]-min>k){
      ans++;
      min=d[i];
      c=1;
    }
  }
  printf("%d\n",ans);
  return 0;
}
	


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char str[200005];
int main() {
	scanf("%s", str);
	int n = strlen(str);
	for (int i = 0; i < n; ++i) {
		if (str[i] == '?') str[i] = 'D';
	}
	printf("%s\n", str);
}


Measured memory_bytes: 3924
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
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);
        BMaximumDifference solver = new BMaximumDifference();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMaximumDifference {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int min = Integer.MAX_VALUE, max = 0;
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                min = Math.min(min, a);
                max = Math.max(max, a);
            }
            out.println(max - min);
        }

    }
}



Measured memory_bytes: 23252
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	scan(N);
	ll A[100001];
	rep(i,N){
		scan(A[i]);
	}
	sort(A,A+N);
	ll ans=0;
	int mini=1,maxi=N-1;
	ll leftnum=A[0],rightnum=A[0];
	int choose=1;
	while(choose<N){
		ll lmi=abs(leftnum-A[mini]),lma=abs(leftnum-A[maxi]),rmi=abs(rightnum-A[mini]),rma=abs(rightnum-A[maxi]);
		if(lmi>=lma&&lmi>=rmi&&lmi>=rma){
			ans+=lmi;
			leftnum=A[mini];
			mini++;
		}
		else if(lma>=lmi&&lma>=rmi&&lma>=rma){
			ans+=lma;
			leftnum=A[maxi];
			maxi--;
		}
		else if(rmi>=lmi&&rmi>=lma&&rmi>=rma){
			ans+=rmi;
			rightnum=A[mini];
			mini++;
		}
		else{
			ans+=rma;
			rightnum=A[maxi];
			maxi--;
		}
		choose++;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 1024
from sys import stdin
from collections import deque
readline = stdin.readline
h, w = map(int, readline().split())
w += 1
dp = [list(map(int, readline().split())) + [1] for _ in range(h)]
for i in range(h):
    for j in range(w):
        dp[i][j] ^= 1
for i in range(1, h):
    for j in range(w):
        if dp[i][j]:
            dp[i][j] += dp[i - 1][j]
max_s = 0
for i in range(h):
    stack = deque()
    for j in range(w):
        if (stack[-1][0] if stack else 0) < dp[i][j]:
            stack.append((dp[i][j], j))
        elif stack and stack[-1][0] > dp[i][j]:
            while stack and stack[-1][0] > dp[i][j]:
                height, l = stack.pop()
                s = height * (j - l)
                if max_s < s:
                    max_s = s
            if dp[i][j]:
                stack.append((dp[i][j], l))
print(max_s)

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

int main()
{ 
    LL n,m;
    cin>>n>>m;
    if(n%2==1){
    LL x=n/2;
    LL y=n/2+1;
    for(int i=0;i<m;i++){
        cout<<x<<' '<<y<<endl;
        x--;y++;
    }
    return 0;
    }
    else{
    LL x=n/2;
    LL y=n/2+1;
    LL k;
    if(m%2==0){k=m/2;}
    else{k=m/2+1;}
    for(int i=0;i<k;i++){
        cout<<x<<' '<<y<<endl;
        x--;y++;
    }
    x=1;
    y=n-1;
    for(int i=0;i<m-k;i++){
        cout<<x<<' '<<y<<endl;
        x++;y--;
    }
    return 0;
    }
}

Measured memory_bytes: 3608
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        par[x] += par[y]
        par[y] = x
        return True
def same(x,y):
    return find(x) == find(y)
def size(x):
    return -par[find(x)]
n = int(input())
par = [-1]*n
p = []
edge = []
for i in range(n):
    x,y = map(int,input().split())
    p.append([x,y,i])
p.sort(key=lambda x:x[0])
for i in range(n-1):
    x_0,_,j=p[i]
    x_1,_,k=p[i+1]
    edge.append([x_1-x_0,j,k])
p.sort(key=lambda x:x[1])
for i in range(n-1):
    _,y_0,j=p[i]
    _,y_1,k=p[i+1]
    edge.append([y_1-y_0,j,k])
edge.sort()
ans = 0
for i in range(len(edge)):
    cost,u,v = edge[i]
    if not same(u,v):
        unite(u,v)
        ans+=cost
print(ans)

Measured memory_bytes: 126280
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end() 
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define rep(i, n) for(int i=0;i<(n);++i)
#define repp(i, a, b) for(int i=(a);i<=(b);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int dp[100][100][2];
int solve() {
	int h,w;cin >>h>>w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	rep(i, h) rep(j, w) rep(k, 2) {
		int &D = dp[i][j][k];
		if(k == 0) {
			if(s[i][j] == '#') {
				D = inf;
				continue;
			}
			if(!i&&!j) {
				D = 0;
			} else if(!i) {
				D = min(dp[i][j-1][0], dp[i][j-1][1]);
			} else if(!j) {
				D = min(dp[i-1][j][0], dp[i-1][j][1]);
			} else D = min(min(dp[i][j-1][0], dp[i][j-1][1]), min(dp[i-1][j][0], dp[i-1][j][1]));
		} else {
			if(s[i][j] == '.') {
				D = inf;
				continue;
			}
			if(!i&&!j) {
				D = 1;
			} else if(!i) {
				D = min(dp[i][j-1][0]+1, dp[i][j-1][1]);
			} else if(!j) {
				D = min(dp[i-1][j][0]+1, dp[i-1][j][1]);
			} else D = min(min(dp[i][j-1][0]+1, dp[i][j-1][1]), min(dp[i-1][j][0]+1, dp[i-1][j][1]));
		}
	}
	cout << min(dp[h-1][w-1][0], dp[h-1][w-1][1]);
}

int main() {
	fastio;
	solve();
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;

struct BIT{
	int size;
	vector<int> bit;
	BIT(){size = 0;}
	BIT(int s){
		size = s;
		bit.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) bit[i] = 0;
	}
	int query(int i){
		int ret = 0;
		while(i > 0){
			ret += bit[i];
			i -= i&(-i);
		}
		return ret;
	}
	void add(int i, int x){
		while(i <= size){
			bit[i] += x;
			i += i&(-i);
		}
	}
};

llint n;
llint p[500005];
llint u[500005];
bool used[500005];
llint lcnt[500005], rcnt[500005];
BIT bit(500005);
llint qcnt;

llint fact[500005], fact_inv[500005];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < 500005; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	for(int i = 0; i < 500005; i++){
		fact_inv[i] = modpow(fact[i], mod-2);
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	make_fact();
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> p[i];
	
	for(int i = 1; i <= n; i++){
		if(p[i] != 0) used[p[i]] = true;
		else qcnt++;
	}
	
	for(int i = 1; i <= n; i++){
		lcnt[i] = lcnt[i-1];
		if(!used[i]) lcnt[i]++;
	}
	for(int i = n; i >= 1; i--){
		rcnt[i] = rcnt[i+1];
		if(!used[i]) rcnt[i]++;
	}
	llint fsum = 0;
	for(int i = 1; i <= n; i++) if(!used[i]) fsum += i-1, fsum %= mod;
	
	llint q = 0, rsum = 0;
	for(int i = 1; i <= n; i++){
		if(p[i] == 0){
			if(qcnt >= 2){
				u[i] += q * comb(qcnt, 2) % mod * fact[qcnt-2] % mod;
				u[i] %= mod;
			}
			u[i] += rsum * fact[qcnt-1] % mod, u[i] %= mod;
			q++;
		}else{
			u[i] += bit.query(p[i]) * fact[qcnt] % mod, u[i] %= mod;
			if(qcnt >= 1) u[i] += q * lcnt[p[i]] % mod * fact[qcnt-1] % mod, u[i] %= mod;
			bit.add(p[i], 1);
			rsum += rcnt[p[i]], rsum %= mod;
		}
	}
	
	for(int i = 1; i <= n; i++){
		llint tmp;
		if(p[i] != 0) tmp = fact[qcnt] * (p[i]-1) % mod;
		else tmp = fsum * fact[qcnt-1] % mod;
		tmp += mod - u[i], tmp %= mod;
		u[i] = tmp;
	}
	
	llint ans = 0;
	for(int i = 1; i <= n; i++){
		ans += fact[n-i] * u[i] % mod, ans %= mod;
	}
	ans += fact[qcnt], ans %= mod;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 26240
#include <stdio.h>
#include <stdlib.h>
#define INFINITY 1000000001

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int nn=0;

main(){
  int n, *arryA, i;

  scanf("%d", &n);
  arryA = (int *)malloc(sizeof(int) * n);
  for(i=0; i<n; i++) scanf("%d", arryA+i);

  mergeSort(arryA, 0, n);
  for(i=0; i<n-1; i++) printf("%d ", arryA[i]);
  printf("%d\n%d\n", arryA[i], nn);
 
  return 0;
}

void merge(int *arryA, int left, int mid, int right){
  int n1, n2, i, j, k, *arryL, *arryR;

  n1 = mid - left;
  n2 = right - mid;

  arryL = (int *)malloc(sizeof(int)*(n1 + 1));
  arryR = (int *)malloc(sizeof(int)*(n2 + 1));
  for(i=0; i<n1; i++) arryL[i] = arryA[left+i];
  for(i=0; i<n2; i++) arryR[i] = arryA[mid+i];
  arryL[n1] = INFINITY;
  arryR[n2] = INFINITY;

  /* printf("**merge(%d, %d, %d) n(L)=%d\n", left, mid, right, n1);
  for(i=0; i<(n1+1); i++) printf("%d ", arryL[i]);
  printf("\n");
  printf("**merge(%d, %d, %d) n(R)=%d\n", left, mid, right, n2);
  for(i=0; i<(n2+1); i++) printf("%d ", arryR[i]);
  printf("\n\n");*/

  i=0;//L
  j=0;//R

  for(k=left; k<right; k++){
    nn++;
    if(arryL[i] <= arryR[j]){
      arryA[k] = arryL[i++];
    }
    else
      arryA[k] = arryR[j++];
  }
}

void mergeSort(int *arryA, int left, int right){
  int mid;

  if(left+1 < right){
    mid = (right + left) / 2;
    mergeSort(arryA, left, mid);
    mergeSort(arryA, mid, right);
    merge(arryA, left, mid, right);
  }
}

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

int parity(int n){
  if(n*n*n*n%10 == 1)
    return 1;
  else
    return 0;
}

int power(int x, int y){
  int64_t n = 1ll;
  for(int i = 0; i < y; i++)
    n *= x;
  return n;
}
int digit(int x, int y){
  return x%power(10,y+1)/power(10,y);
}

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> dis(k);
  for(int i = 0; i < k; i++)
    cin >> dis.at(i);
  vector<int> like;
  int j = 0;
  for(int i = 0; i < 10; i++){
    if(i == dis.at(j))
      j = min(j+1,k-1);
    else
      like.push_back(i);
  }
  //cout << like.size() << endl;
  
  vector<int> likes;
  if(k == 9){
    int l = like.at(0);
    likes.push_back(l);
    for(int i = 0; i < 6; i++)
      likes.push_back(likes.at(i)*10+l);
  }
  else{
    for(int i = 1; i < 6; i++){
      if(i == 1){
        for(int l : like)
          likes.push_back(l);
      }
      else{
        for(int l : like){
          for(int j = (power(10-k,i-1)-1)/(9-k)-1; j < (10-k)*(power(10-k,i-1)-1)/(9-k); j++){
            likes.push_back(l*power(10,i-1)+likes.at(j));
          }
        }
      }
    }
  }
  for(int nn : likes){
    if(nn >= n){
      cout << nn << endl;
      break;
    }
  }
}

Measured memory_bytes: 892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// ここにコードを挿入
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int t = 0;
		int L = 0, R = N;
		if (M == 1) {
			int c = sc.nextInt();
			int d = sc.nextInt();
			t = d - c + 1;
		} else {
			for (int i = 0; i < M; i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				if (L <= a && b <= R) {
					L = a;
					R = b;
					t = R - L + 1;
				} else if (a <= L && R <= b) {
					t = R - L + 1;
				} else if ((L <= a && a <= R) && R < b) {
					L = a;
					t = R - L + 1;
				} else if ((L <= b && b <= R) && a < L) {
					R = b;
				} else if (b < L || R < a) {
					t = 0;
					break;
				} else {
					L = a;
					R = b;
				}

			}
		}
		System.out.println(t);
	}

}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  if (a < b) {
    return Gcd(b,a);
  }
  if (b == 0) {
    return a;
  }
  else {
    return Gcd(b,a%b);
  }
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}


//-------------------------------------------

int main() {
  int N,M;
  bool t=false;
  cin >> N >> M;
  VI A(N);
  VB B(N);
  
  REP(i,M){
    int s,c;
    cin >> s >> c;
    
    if(s > N){
      t = true;
      break;
    }
    
    if(B.at(s-1)){
      if(c != A.at(s-1)){
        t = true;
        break;
      }
    }
    
    if(N != 1 && s==1 && c==0){
      t = true;
        break;
    }
    
    A.at(s-1) = c;
    B.at(s-1) = true;
    
  }
  
  if(N != 1 && A.at(0)==0){
     A.at(0)=1;
  }
  
  if(t) cout << -1 << endl;
  else {
    REP(i,N){
      cout << A.at(i);
    }
    cout << endl;
  }
  
}


Measured memory_bytes: 256
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    ll ans = 0;
    REP(i, s.size() / 2) {
        if (s[i] != s[s.size() - 1 - i]) ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
// abc144_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (numelic_limit<ll>::max())
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N;
    cin >> N;

    ll ans = numeric_limits<ll>::max();

    for (ll i = 1; i * i <= N; i++){
        if (N % i == 0){
            ans = min(ans, i + N/i - 2);
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pt;

#define fi first
#define se second
#define lson (p<<1)+1
#define rson (p<<1)+2
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll a,b, k, t;

int main () {
    fastIO;
    cin >> a >> b >> k;
    t = min(a, k);
    a -= t; k -= t;
    t = min(b, k);
    b -= t;
    cout << a << " " << b;
}


Measured memory_bytes: 256
//In The Name Of Godd
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef pair<ll, ll> ii;
typedef pair<int, ii> iii;
typedef pair<double, double> dd;
typedef pair<dd, double> ddd;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<dd> vdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;

#define forn(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define inf 100000000000
#define eps 1e-9
const int maxn = 2e5;
ll dp[maxn];
ll cst[maxn];

int main() {
  int n; cin >> n;
  forn(i, n) cin >> cst[i], dp[i] = inf;
  dp[0] = 0;
  forn(i, n) {
      if(i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(cst[i] - cst[i + 2]));
      if(i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + abs(cst[i] - cst[i + 1]));
  }
  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <string>

using namespace std;

int main(){
  long long n, k;
  cin >> n >> k;
  n = n%k;
  cout << min(n, k - n);
}


Measured memory_bytes: 256
/**
 *    author        : Saurav Paul 
 *    created       : August 03, 2020 11:41 AM
 *    Problem Name  : E - Logs
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc174/tasks/abc174_e
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
using namespace std;

#define bug()				  debug() <<
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef PAUL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define dbg(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif


int main(){
    ios_base::sync_with_stdio(false);

    int n , k ;
    cin >> n >> k ;

    vector<long long> v(n) ;

    for(auto &x : v){
        cin >> x ;
    }

    sort(v.begin(),v.end() , [](int a, int b){
            return (a>b) ;
    }) ;

    long long l = 1 , r = v[0] ;
    while(l <= r){
        long long mid = (l + r) >> 1;

        bool ok = true ;
        int temp = k ;

        bug() dbg(mid) ;
        for(int i = 0 ; i < n; i++){
            if(v[i] <= mid) break ;

            long long t = (v[i]-1)/mid  ;

            temp -= t ;
            if(temp < 0){
                ok = false ;
                break ;
            }
        }


        if(ok == false){
            l = mid + 1;
        }
        else {
            r = mid - 1;
        }

        bug() dbg(mid) dbg(l) dbg(r) dbg(ok) ;
        /* cout << l << " " << r  << " " << ok  << " "<<temp <<endl; */

    }

    cout << l << endl ;

    return 0 ;
}


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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    int n = s.length();
    for (int i = 0; i < n/2; i++) {
        if (s.at(i) != s.at(n-i-1))
            ans += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  int i_s,i_e;
  i_s = 200000;
  i_e = 0;
  cin >> s;
  for(int i = 0; i<s.size(); i++){
    if(s[i] == 'A' && i_s > i)i_s = i;
    if(i_s<i && s[i] == 'Z' && i_e < i )i_e = i;
  }
  cout << i_e - i_s +1 << endl;
}


Measured memory_bytes: 640
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    VI V(3);
    REP(i,3)
    {
        cin >> V[i];
    }
    SORT(V);
    if (V[0]==V[1]) cout << V[2] << endl;
    else if (V[2]==V[1]) cout << V[0] << endl;
  
    return 0;
}



Measured memory_bytes: 256
n,m = map(int,input().split())
ka = [0] * n
for i in range(m):
  a,b = map(int,input().split())
  if a == 1:
    if ka[b-1] == 1:
      print("POSSIBLE")
      break
    else:
      ka[b-1] = 1
  if b == n:
    if ka[a-1] == 1:
      print("POSSIBLE")
      break
    else:
      ka[a-1] = 1
else:
  print("IMPOSSIBLE")

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

int main(){
	int N,T,A;
	cin >> N >> T >> A;
	int H[N];
	int D[N];
	for(int i=0;i<N;i++){
		cin >> H[i];
		D[i]=abs(1000*(T-A)-6*H[i]);
	}
	int ans=0;
	for(int i=1;i<N;i++){
		ans=D[i]<D[ans]?i:ans;
		
	}
	cout << ans+1 << endl;
    return 0;

}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
	int a[3];
	scanf("%d%d%d", &a[0], &a[1], &a[2]);
	
	for(int i=0;i<3;i++){
		if(a[i%3]==a[(i+1)%3] && a[(i+1)%3]!=a[(i+2)%3]){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <math.h> 
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll so[1000010];
int main() {
	so[1]=1;
	for(ll i=2;i<1000010;i++){
		ll now=i;
		if(so[i]!=0){
			continue;
		}
		for(ll j=1;j*i<1000010;j++){
			so[i*j]=now;
		}
	}
	ll n;
	cin>>n;
	ll ch[10010];
	for(ll i=0;i<n;i++){
		cin>>ch[i];
	}
	ll ke[1000010]={};
	for(ll i=0;i<n;i++){
		ll now=ch[i];
		map<ll,ll>q;
		while(now!=so[now]){
			q[so[now]]++;
			now/=so[now];
		}
		q[now]++;
		for(auto itr=q.begin();itr!=q.end();itr++){
			ll num=itr->first;
			ll val=itr->second;
			ke[num]=max(ke[num],val);
		}
	}
	ll lcm=1;
	for(ll i=2;i<1000010;i++){
		lcm*=modpow(i,ke[i],inf);
		lcm%=inf;
	}
	//cout <<lcm;
    // a を 10000000007 で割ってから b の逆元をかけて計算
    //a %= MOD;
    //cout << a * modinv(b, MOD) % MOD << endl;
    ll ans=0;
    for(ll i=0;i<n;i++){
    	ll now=ch[i];
    	ll cnt=lcm*modinv(now,inf)%inf;
    	ans+=cnt;
    	ans%=inf;
    }
    cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 19272
#include<iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int n,cnt;
int x[202020],y[202020];
struct Pa {
	int x,y;
	char dir;
}p[202020];
char dir[202020];
char s[20];
bool cmp1(Pa A,Pa B) {
	if (A.y != B.y) {
		return A.y < B.y;
	}
	return A.x < B.x;
}
bool cmp2(Pa A,Pa B) {
	if (A.x != B.x) {
		return A.x < B.x;
	}
	return A.y < B.y;
}
bool cmp3(Pa A,Pa B) {
	if (A.x+A.y != B.x+B.y) {
		return A.x+A.y < B.x+B.y;
	}
	return A.x < B.x;
}
bool cmp4(Pa A,Pa B) {
	if (A.x-A.y != B.x-B.y) {
		return A.x-A.y < B.x-B.y;
	}
	return A.x < B.x;
}
void get(char A,char B) {
	cnt = 0;
	for (int i = 1;i <= n; i++) {
		if (dir[i] == A || dir[i] == B) {
			p[++cnt].x = x[i];
			p[cnt].y = y[i];
			p[cnt].dir = dir[i];
		}
	}
} 
int main(){
	scanf("%d",&n);
	for (int i = 1;i <= n; i++) {
		scanf("%d%d%s",&x[i],&y[i],s);
		dir[i] = s[0];
		p[i].x = x[i];
		p[i].y = y[i];	
		p[i].dir = dir[i];
	}
	int ans = 100000000;
	get('L','R');
	sort(p+1,p+cnt+1,cmp1);
	for (int i = 1;i < cnt; i++) {
		if (p[i].y == p[i+1].y && p[i].dir == 'R' && p[i+1].dir == 'L') {
			ans = min(ans,5*(p[i+1].x - p[i].x));
		}
	}
	get('U','D');
	sort(p+1,p+cnt+1,cmp2);
	for (int i = 1;i < cnt; i++) {
		if (p[i].x == p[i+1].x && p[i].dir == 'U' && p[i+1].dir == 'D') {
			ans = min(ans,5*(p[i+1].y - p[i].y));
		}
	}
	get('L','D');
	sort(p+1,p+cnt+1,cmp3);
	
	for (int i = 1;i < cnt; i++) {
		if (p[i].x+p[i].y == p[i+1].x +p[i+1].y && p[i].dir == 'D' && p[i+1].dir == 'L') {
			ans = min(ans,10*(p[i+1].x - p[i].x));
		}
	}
	get('U','R');
	sort(p+1,p+cnt+1,cmp3);
	for (int i = 1;i < cnt; i++) {
		if (p[i].x+p[i].y == p[i+1].x +p[i+1].y && p[i].dir == 'R' && p[i+1].dir == 'U') {
			ans = min(ans,10*(p[i+1].x - p[i].x));
		}
	}
	get('D','R');
	sort(p+1,p+cnt+1,cmp4);
	for (int i = 1;i < cnt; i++) {
		if (p[i].x-p[i].y == p[i+1].x -p[i+1].y && p[i].dir == 'R' && p[i+1].dir == 'D') {
			ans = min(ans,10*(p[i+1].x - p[i].x));
		}
	}
	get('U','L');
	sort(p+1,p+cnt+1,cmp4);
	for (int i = 1;i < cnt; i++) {
		if (p[i].x-p[i].y == p[i+1].x -p[i+1].y && p[i].dir == 'U' && p[i+1].dir == 'L') {
			ans = min(ans,10*(p[i+1].x - p[i].x));
		}
	}
	if (ans != 100000000) {
		printf("%d\n",ans);
	}
	else
	printf("SAFE");
    return 0;
}

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

using namespace std;

const int N = 29;

int p[N];

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    int ans(0);
    for (int i = 1; i < n - 1; ++i) {
        if (p[i] > p[i - 1] && p[i] < p[i + 1])
            ++ans;
        else if (p[i] < p[i - 1] && p[i] > p[i + 1])
            ++ans;
    }
    cout << ans;
    return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll d; cin >> d;

    vector<ll> c(26);
    for (ll i = 0; i < 26; ++i) {
        cin >> c[i];
    }

    vector<vector<ll>> s(d, vector<ll>(26));
    for (ll i = 0; i < d; ++i) {
        for (ll j = 0; j < 26; ++j) {
            cin >> s[i][j];
        }
    }

    vector<ll> t(d);
    for (ll i = 0; i < d; ++i) {
        ll idx = 0;
        ll mx = 0;
        for (ll j = 0; j < 26; ++j) {
            if (mx < s[i][j]) {
                mx = s[i][j];
                idx = j;
            }
        }
        t[i] = idx;
    }

    vector<ll> score(d, 0);
    vector<vector<ll>> last(d, vector<ll>(26, 0));

    auto re_score = [&](ll start) {
        for (ll i = start; i < d; ++i) {
            score[i] = (i - 1 >= 0 ? score[i - 1] : 0) + s[i][t[i]];

            if (i - 1 >= 0) {
                last[i] = last[i - 1];
            } else {
                for (ll j = 0; j < 26; ++j) {
                    last[0][j] = 0;
                }
            }

            last[i][t[i]] = i + 1;

            ll j = i + 1;

            for (ll k = 0; k < 26; ++k) {
                score[i] -= c[k] * (j - last[i][k]);
            }
        }
    };

    re_score(0);

    ll mx_score = score[d - 1];
    for (ll i = 0; i < d; ++i) {
        for (ll j = 0; j < 26; ++j) {
            ll tmp = t[i];

            t[i] = j;
            re_score(i);

            if (mx_score > score[d - 1]) {
                t[i] = tmp;
                re_score(i);
            }
        }
    }

    for (ll i = 0; i < d; ++i) {
        cout << t[i] + 1 << endl;
    }
}

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

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

    int N, X;
    cin >> N >> X;

    vector<int> L(N);
    vector<int> Zahyou(N + 1);
    int count;
    int L_n;

    Zahyou[0] = 0;

    for (int n = 0; n < N; n++) {
        cin >> L[n];
    }

    for (int n = 1; n < N + 1; n++) {
        //cout << L[n - 1] << '\n';
        Zahyou[n] = Zahyou[n - 1] + L[n - 1];
    }

    for (int n = 0; n < N + 1; n++) {
        //cout << Zahyou[n] << '\n';
        if (Zahyou[n] > X) {
            count = n;
            break;
        }
    }

    if (Zahyou[N] <= X) {
        count = N + 1;
    }

    cout << count << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int ar[5];
    for(int i=0; i<5; i++)
    {
        cin>>ar[i];
    }
    for(int i=0; i<5; i++)
    {
        if(ar[i]==0)
        {
            cout<<i+1<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3600
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let n=read::<i32>();
    let mut t=0.0;
    for _ in 0..n{
        let a=read::<f32>();
        let s=read::<String>();
        t+=a*if s=="BTC"{38e4}else{1.0};
    }
    println!("{}",t);
}

Measured memory_bytes: 4352
#include <stdio.h>

int main(){
   int n,x,y,a[2001],i,j,z,p;

   scanf("%d %d %d",&n,&x,&y);
   for (i=1;i<=n;i++) a[i]=0;
   z=(x+y+1)/2;
   for (i=1;i<n;i++)
      for (j=i+1;j<=n;j++) {
         if (i<x) p=x-i;
         else     p=i-x;
         if (j>y) p+=j-y+1;
         else     p+=y-j+1;
         if (p<j-i) a[p]++;
         else       a[j-i]++;
      }
   for (i=1;i<n;i++)
      printf("%d\n",a[i]);
   return 0;
}


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

long long GCD(long long a,long long b){
    if(b!=0){
        GCD(b,a%b);
    }
    else{
        return a;
    }

}

int main()
{
    long long a,b,x;

    while(scanf("%lld %lld",&a,&b)!=EOF){
        if(a==0 || b==0){
            printf("0 0\n");
            continue;
        }
        else if(a<b){
            x=a;
            a=b;
            b=x;
        }
        x=GCD(a,b);
        printf("%lld %lld\n",x,(a/x)*b);

    }
}

Measured memory_bytes: 1024