akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  ABC172B
#include <iostream>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int main(int argc, const char * argv[]) {
    string s,t;
    cin>>s>>t;
    int ans=0;
    rep(i,s.size()){
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll MOD = 1000000007;
const ll N=1e5+9;
int main()
{
    FASTINOUT;
    ll x,k;
    cin>>x>>k;
    ll m=(x-1)*(x-2)/2;
    if (m<k)
    {
        cout<<-1<<endl;
        return 0;
    }
    cout<<x-1+m-k<<endl;
    for (int i=2; i<=x; i++)
        cout<<1<<" "<<i<<endl;
    int f=2,s=3;
    for (int i=0;i<(x-1)*(x-2)/2-k;i++)
    {
        if (s>x){
            f++;
            s=f+1;
        }
        cout<<f<<" "<<s<<endl;
        s++;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int main()
{
    using namespace std;
    //----------------
    
    string s;
    cin >> s;
    int min = 1000;
    for( int i= 0, end = s.length() - 2; i < end; ++i )
    {
        int n3 = stoi( s.substr( i, 3 ) );
        int sub = abs( n3-753  );
        if( min > sub )
        {
            min = sub;
        }
    }
    cout << min;
    
    //----------------
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,l,m) for(int i=l;i<=(int)(m);i++)

int main(){
  int L,R,d,count=0;

  scanf("%d",&L);
  scanf("%d",&R);
  scanf("%d",&d);

  rep(i,L,R){
    if(i%d==0)count++;
  }
  printf("%d\n",count);

  return 0;
}

  


Measured memory_bytes: 1728
import collections
import bisect

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

D.sort()
T2 = collections.Counter(T)

for i in T2.keys():
    if T2[i] > bisect.bisect_right(D, i) - bisect.bisect_left(D, i):
        print("NO")
        exit()

print("YES")


Measured memory_bytes: 41700
#include<cmath>
#include<cstdio>
#include<cassert>
#include<cstring>
#include<algorithm>
#define MN 51
#define Cx 0.03
#define Cy 0.03
#define eps 1e-7
using namespace std;

int read_p,read_ca;
inline int read(){
    read_p=0;read_ca=getchar();
    while(read_ca<'0'||read_ca>'9') read_ca=getchar();
    while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
    return read_p;
}
int n,m;
char a[100][100],b[100][100];
int main(){
	register int i,j,k,l;
	n=read();m=read();
	for (i=0;i<n;i++) scanf("%s",a[i]);
	for (i=0;i<m;i++) scanf("%s",b[i]);
	for (i=0;i<=n-m;i++)
	for (j=0;j<=n-m;j++){
		int o=1;
		for (k=0;k<m;k++)
		for (l=0;l<m;l++)
		if (a[i+k][j+l]!=b[k][l]) o=0;
		if (o) return puts("Yes"),0;
	}
	puts("No");
}

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

using namespace std;

void doc() {
    freopen("OB.inp", "r", stdin);
    freopen("OB.out", "w", stdout);
}

const   int MaxN = 1e5 + 5;

void solve(){
    int n, K;
    cin >> n >> K;
    int a[n];
    bool check[K + 1];
    memset(check, false, sizeof(check));
    for(int i = 0; i < n; i++){
        cin >> a[i];
        check[a[i]] = true;
    }
    for(int i = 0; i <= K; i++){
        if (!check[i]){
            for(int j = 0; j < n; j++){
                if (i + a[j] > K) break;
              //  cout << i << " " << j << '\n';
                check[i + a[j]] = true;
                if (check[K]){
                    cout << "First";
                    return;
                }
            }
        }
    }
    cout << "Second";
}

int main()
{
//    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    //doc();
    solve();
}



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

int main() {
	int n, k;
	cin>>n>>k;
	vector<int> arr(n);
	for(int i = 0; i<n; i++){
	    cin>>arr[i];
	}
	
	vector<int> dp(n, INT_MAX);
	dp[0] = 0;
	for(int i = 1; i < n; i++){
	    
	    for(int j = 1; i-j >= 0 && j<=k; j++){
	        dp[i] = min(abs(arr[i] - arr[i-j]) + dp[i-j], dp[i]);
	    }
	}
	cout<<dp[n-1];
	return 0;
}


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

using namespace std;

vector<int> v;

int calc(int a, int b)
{
    int tmp;
    int r;

  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main()
{
    int N, X;

    cin >> N >> X;

    int x = 0;

    int g = 0;

    for(int i = 0; i < N; i++)
    {
        cin >> x;

        x = abs(x - X);

        if(i == 0)
        {
            g = x;
        }
        else
        {
            g = calc(g, x);
        }
    }

    cout << g << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int c[3][3] = {};
    for (int i=0; i<3; i++)
        for (int j=0; j<3; j++)
            cin >> c[i][j];
    for (int i=0; i<2; i++) {
        int tmp = c[i][0] - c[i+1][0];
        for (int j=1; j<3; j++)
            if (tmp != c[i][j] - c[i+1][j]) {
                cout << "No" << endl;
                return 0;
            }
    }
    for (int i=0; i<2; i++) {
        int tmp = c[0][i] - c[0][i+1];
        for (int j=1; j<3; j++)
            if (tmp != c[j][i] - c[j][i+1]) {
                cout << "No" << endl;
                return 0;
            }
    }
    puts("Yes");
}

Measured memory_bytes: 256
N, K = map(int, raw_input().split())
V = {}
for i in range(N):
    a, b = map(int, raw_input().split())
    if not a in V:
        V[a] = 0
    V[a] += b
for v, num in sorted(V.items()):
    K -= num
    if K <= 0:
        print v
        break

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

int main() {
	int n, x, y;
	cin >> n >> x >> y;
	x--;
	y--;

	vector<int> res(n, 0);
	REP(i, n) for (int j = i + 1; j < n; j++) {
		int mini = min(min(abs(j - i), abs(x - i) + 1 + abs(j - y)), abs(y - i) + 1 + abs(j  - x));
		res[--mini]++;
	}

	REP(i, n - 1) cout << res[i] << '\n';
    return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 100005
using namespace std;
class DSJ {
public:
    int ngroups;
    vector<int> fa,sz;
    DSJ() {}
    DSJ(int _n) {
        ngroups = _n;
        fa = vector<int> (_n+1);
        sz = vector<int> (_n+1, 1);
        REP(i,0,_n) fa[i] = i;
    }
    int find(int x) {
        return x==fa[x] ? x : fa[x]=find(fa[x]);
    }
    int size(int x) {
        return sz[find(x)];
    }
    void con(int x,int y) {
        x = find(x);
        y = find(y);
        if (x==y) return;
        fa[x] = y;
        sz[y] += sz[x];
        ngroups--;
    }
    int groups() {
        return ngroups;
    }
}dsj;
int n,px[M],py[M];
vector<int> xs[M], ys[M];
int main()
{
    while (~scanf("%d", &n)) {
        REP(i,0,M-1) {
            xs[i].clear();
            ys[i].clear();
        }
        REP(i,1,n) {
            int x,y;
            scanf("%d %d",&x,&y);
            xs[x].push_back(i);
            ys[y].push_back(i);
            px[i] = x;
            py[i] = y;
        }

        dsj = DSJ(n);
        REP(i,0,M-1) REP(j,1,(int)xs[i].size()-1) dsj.con(xs[i][j-1], xs[i][j]);
        REP(i,0,M-1) REP(j,1,(int)ys[i].size()-1) dsj.con(ys[i][j-1], ys[i][j]);

        vector<int> childs[M];
        long long ans = 0;
        REP(i,1,n) childs[dsj.find(i)].push_back(i);
        REP(i,1,n) if(dsj.find(i)==i) {
            set<int> xx, yy;
            for (int j:childs[i]) {
                xx.insert(px[j]);
                yy.insert(py[j]);
            }

            ans += (long long)xx.size() * yy.size();
        }
        printf("%lld\n", ans-n);
    }
    return 0;
}


Measured memory_bytes: 17016
import collections
N = int(input())
edges = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a-1].append([b-1,i])
    edges[b-1].append([a-1,i])
q = collections.deque()
q.append([0,-1,-1])
colors = [0]*(N-1)
while len(q) != 0:
    v, color, num = q.popleft()
    if colors[num] == 0 and color != -1:
        colors[num] = color
    next_color = 0
    for w in edges[v]:
        if colors[w[1]] != 0:
            continue
        next_color += 1
        if next_color == colors[num]:
            next_color += 1
        q.append([w[0],next_color,w[1]])
print(len(set(colors)))
for i in colors:
    print(i)

Measured memory_bytes: 106768
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N, T;
    cin >> N >> T;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    ll ans = T;
    for (int i = 0; i < N - 1; i++) {
        ans += min(T, a[i+1] - a[i]);
    }

    cout << ans << '\n';
}


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

double dp[3001][3001];

double coinsF(double * arr, int i, int x, double dp[][3001]){
	if(x == 0){
		return 1;
	}
	if(i == 0){
		return 0;
	}
	if(dp[i][x] > -0.9){
		return dp[i][x];
	}
	return dp[i][x] = arr[i]*coinsF(arr, i-1, x-1, dp) + (1-arr[i])*coinsF(arr, i-1, x, dp);
}



int main(){
	int n;
	cin>>n;
	double * arr = new double[n+1];
	for(int i = 1; i <= n; i++){
		cin>>arr[i];
	}
	

	int heads = (n+1)/2;

	memset(dp, -1, sizeof(dp));


	cout<< fixed << setprecision(10) << coinsF(arr, n, heads, dp);


	return 0;
}


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

int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<vector<int>> d(n);
  rep(i, m) {
    cin >> a >> b;
    a--, b--;
    d[a].push_back(b);
    d[b].push_back(a);
  }

  queue<int> q;
  vector<int> visited(n, -1);
  q.push(0);
  visited[0] = 0;
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    rep(j, d[p].size()) {
      int np = d[p][j];
      if (visited[np] == -1) {
        q.push(np);
        visited[np] = visited[p] + 1;
      }
    }
  }
  rep(i, n) {
    if (visited[i] == -1) {
      cout << "No" << endl;
      return 0;
    }
  }

  //   rep(i, n) cerr << visited[i] << ' ';
  //   cerr << endl;

  vector<P> p1, p2;
  rep(i, n) p1.emplace_back(visited[i], i);
  sort(p1.begin(), p1.end());
  int np = 0, nd = 0;
  rep(i, n) {
    if (p1[i].first == nd) {
      p2.emplace_back(p1[i].second, np);
    } else {
      np = p1[i - 1].second;
      nd++;
      p2.emplace_back(p1[i].second, np);
    }
  }
  sort(p2.begin(), p2.end());
  cout << "Yes" << endl;
  for (int i = 1; i < n; i++) cout << p2[i].second + 1 << endl;

  return 0;
}


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

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

    int n; cin >> n;

    int num = 1;
    int count = 0;
    REP(i, n) {
        int tmp; cin >> tmp;
        if (num == tmp) {
            num++;
            count++;
        }
    }

    if (count == 0) cout << -1 << '\n';
    else cout << n - count << '\n';
    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){
   double a, b; cin >> a >> b;
   int res = ceil((a+b)/2);
   cout << res << ln;
}


Measured memory_bytes: 3668
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)            {dbg,args; cerr<<endl;}
#else
#define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
	template<typename T> debugger& operator , (const T& v)
	{
		cerr<<v<<" ";
		return *this;
	}
} dbg;

void solve(long long H, long long W, vector<string> A){
	int x=0,y=0;
	if (A[0][0]!='#') throw 1;
	A[0][0]='.';
	while(x!=H-1 ||  y!=W-1) {
		if (x<H-1 && A[x+1][y]=='#' && y<W-1 && A[x][y+1]=='#') {
			throw 2;
		}
		if (x<H-1 && A[x+1][y]=='#') {
			++x;
			A[x][y]='.';
		} else if (y<W-1 && A[x][y+1]=='#') {
			++y;
			A[x][y]='.';
		} else throw 3;
	}
	for(const auto& i:A) {
		for(const auto& j:i) {
			if (j=='#') throw 4;
		}
	}
	puts("Possible");
}

int main(){
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	long long W;
	long long H;
	scanf("%lld",&H);
	vector<string> A(H-1+1);
	scanf("%lld",&W);
	for(int i = 0 ; i <= H-1 ; i++){
		cin >> A[i];
	}
	try {
	solve(H, W, A);
	} catch (int flag) {
		debug(flag);
		puts("Impossible");
	}
	return 0;
}



Measured memory_bytes: 256
hoge=input()
ans=[]

while len(hoge):
  if(hoge[0]=="0"):
    ans.append(0)
    hoge=hoge[1:]
  elif(hoge[0]=="1"):
    ans.append(1)
    hoge=hoge[1:]
  else:
    if(len(ans)>0):
      ans=ans[:-1]
    hoge=hoge[1:]

for i in range(len(ans)):
  print(ans[i],end="")
print("")

Measured memory_bytes: 3064
n=int(input())
if n==0:
  print(0)
  exit()
ans=[]
while n!=0:
  n-=1
  ans.append(n%-2)
  n//=(-2)
#print(ans)
tmp=[1*(i==0) for i in ans][::-1]
print("".join(map(str,tmp)))


Measured memory_bytes: 9064
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
 
int main(int argc, const char * argv[]) {
    ll N, P;
    cin >> N >> P;
 
    string S;
    cin >> S;
 
    if (10 % P == 0) {
        ll count = 0;
        for (int i = 0; i < N; i++) {
            if ((S[i] - '0') % P == 0) count += i + 1;
        }
        cout << count << endl;
        return 0;
    }
    
    map<int, ll> rc;
    rc[0] += 1;
    int tmp_r1 = 0;
    int tmp_r2 = 1;
    for (ll i = N - 1; i >= 0; i--) {
        int res = (tmp_r1 + tmp_r2 * (S[i] - '0')) % P;
        rc[res] += 1;
        tmp_r1 = res;
        tmp_r2 = (tmp_r2 * 10) % P;
    }
    
    ll count = 0;
    for (int r = 0; r < P; r++) {
        if (rc[r] < 2) continue;
        ll r1 = (rc[r] % 2 == 0) ? rc[r] / 2 : rc[r];
        ll r2 = (rc[r] % 2 != 0) ? (rc[r] - 1) / 2 : rc[r] - 1;
        count += r1 * r2;
    }
    cout << count << endl;
 
    return 0;
}


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

int main(void) {
    int n;
    cin >> n;
    vector<int> cards(n);
    for (int i = 0; i < n; i++) {
        cin >> cards.at(i);
    }

    sort(cards.begin(), cards.end());
    reverse(cards.begin(), cards.end());

    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            sum += cards.at(i);
        } else {
            sum -= cards.at(i);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    private final static Main main = new Main();

    public static void main(String[] args) {
        main.contest();
    }

    private void contest() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int[] list = new int[n];
        for (int i=0; i<n; ++i) {
            list[i] = sc.nextInt();
        }
        Arrays.sort(list);

        int num = 1;
        int top = list[0];
        int count = 1;
        for (int i=1; i<n; ++i) {
            int t = list[i];
            if (count == c || top+k < t) {
                ++num;
                top = t;
                count = 1;
            } else {
                ++count;
            }
        }
        System.out.println(num);
    }
}


Measured memory_bytes: 48984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    ll n,k; cin>>n>>k;
    ll res=k;
    rep(i,n-1) res*=(k-1);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())
Ans=0
for x in range(A+1):
  for y in range(B+1):
    for z in range(C+1):
      if 500*x + 100*y + 50*z == X:
        Ans += 1

print(Ans)

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

int main()
{
  int long long lmin=2,lmax=1,l=0;
  int N;
  cin >> N;
  if(N==0){
    cout << 2 << endl;
    return 0;
  }
  else if(N==1){
    cout << 1 << endl;
    return 0;
  }
  for(int i=2;i<=N;i++){
    l=lmin+lmax;
    lmin=lmax;
    lmax=l;
  }
  cout << l << endl;
}
  


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

#define int long long
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
//const int MOD = 10000;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
int gcd(int x,int y){if(y==0) return x; return gcd(y, x%y);}
int lcm(int x,int y){return x/gcd(x,y)*y;}

signed main() {
    int n, k;
    cin >> n >> k;
    vector<double> p(n+1);
    p[0] = 0;
    rep(i,n){
        int t; cin >> t;
        p[i+1] = p[i] + (t+1)/2.0;
    }
    
    double ans = 0;
    rep(i,n-k+1){
        ans = max(p[i+k]-p[i], ans);
    }
    
    printf("%.10f\n",ans);
}

Measured memory_bytes: 1792
"use strict"

const main = (input) => {
    input = input.split("\n");
    const N = Number(input[0]);
    const weights = input[1].split(" ").map((weight) => Number(weight));
    const diffs = [];
    for (let i = 0; i < weights.length; i++) {
        const weightsBegin = weights.slice(0, i);
        const weightsEnd = weights.slice(i);
        const S1 = weightsBegin.reduce((sum, weightBegin) => sum + weightBegin, 0);
        const S2 = weightsEnd.reduce((sum, weightEnd) => sum + weightEnd, 0);
        const diff = Math.abs(S1 - S2);
        diffs.push(diff);
    }
    const minDiff = diffs.reduce((a, b) => a < b ? a : b);
    console.log(minDiff);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N, K;
		N=sc.nextInt();
		K=sc.nextInt();
		sc.close();

		if(N%K==0) {
			System.out.println(0);
		}
		else {
			System.out.println(1);
		}
	}
}


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

#define MAX 35

int h, w, n;
/*
bool annihilation(vector<string> &field, int y, int x){
  if(field[y][x] == '.') return false;
  
  for(int ii = -1; ii <= 1; ii++){
    for(int jj = -1; jj <= 1; jj++){
      if(!ii && !jj) continue;
      if(ii && jj) continue;
      int con = 0;

      int i = ii, j = jj;
      for(int nx = x, ny = y; 0 <= nx && nx < w && 0 <= ny && ny < h; nx += j, ny += i, con++){
	if(field[ny][nx] != field[y][x]) break;
	if(con + 1>= n) return true;
      }
      
      i *= -1, j *= -1;
      
      for(int nx = x+j, ny = y+i; 0 <= nx && nx < w && 0 <= ny && ny < h; nx += j, ny += i, con++){
	if(field[ny][nx] != field[y][x]) break;
	if(con + 1>= n) return true;
      }

      if(con >= n) return true;
    }
  }

  return false;
}
*/

bool annihilation(vector<string> &field, int y, int x){
  if(field[y][x] == '.') return false;
  
  int dxy[2] = {0,1};
  
  for(int i = 0; i < 2; i++){
    int ty = dxy[i], tx = dxy[1-i];
    int con = 1;
    
    for(int nx = x + tx, ny = y + ty; 0 <= nx && nx < w && 0 <= ny && ny < h; nx += tx, ny += ty){
      if(field[ny][nx] != field[y][x]) break;
      con++;
    }
    tx *= -1, ty *= -1;
    for(int nx = x + tx, ny = y + ty; 0 <= nx && nx < w && 0 <= ny && ny < h; nx += tx, ny += ty){
      if(field[ny][nx] != field[y][x]) break;
      con++;
    }

    if(con >= n) return true;
  }

  return false;
}

bool check(vector<string> field){

  for(int i = 0; i < w; i++){
      for(int j = 0, k = 0; j < h; j++){
	if(field[h-1-j][i] != '.') continue;
	for(k = max(j+1,k); k < h; k++){
	  if(field[h-1-k][i] != '.'){
	    swap(field[h-1-j][i], field[h-1-k][i]);
	    break;
	  }
	}
	if(k == h) break;
      }
    }
  
  while(true){
    bool flag[MAX][MAX] = {}, cont = false;
    int con = 0;
    
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(annihilation(field,i,j)){
	  flag[i][j] = true;
	  cont = true;
	}
	if(field[i][j] == '.' || flag[i][j] == true) con++;
	
      }
    }

    if(con == h*w) return true;
    if(!cont) return false;
    
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(flag[i][j]){
	  field[i][j] = '.';
	}
      }
    }

    for(int i = 0; i < w; i++){
      for(int j = 0, k = 0; j < h; j++){
	if(field[h-1-j][i] != '.') continue;
	for(k = max(j+1,k); k < h; k++){
	  if(field[h-1-k][i] != '.'){
	    swap(field[h-1-j][i], field[h-1-k][i]);
	    break;
	  }
	}
	if(k == h) break;
      }
    }
  }
  
  return false;
}

signed main(){

  vector<string> field;
  
  cin>>h>>w>>n;

  field.resize(h);

  for(int i = 0; i < h; i++){
    cin>>field[i];
  }
  /*
   if(check(field)){
     cout<<"YES"<<endl;
     return 0;
   }
  */
   
   for(int i = 0; i < h; i++){
    for(int j = 0; j < w-1; j++){
      // if(field[i][j] == '.' || field[i][j+1] == '.') continue;
      
      if(field[i][j] == '.' && field[i][j+1] == '.') continue;
      
      swap(field[i][j],field[i][j+1]);

      if(check(field)){
	cout<<"YES"<<endl;
	return 0;
      }
      
      swap(field[i][j],field[i][j+1]);
    }
  }

  cout<<"NO"<<endl;
  
  return 0;
}



Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


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

    int n=s.size();
    vector<int> ans(n,1);

    rep(i,n-1){
        if(s[i]=='R' && s[i+1]=='R'){
            ans[i+2]+=ans[i];
            ans[i]=0;
        }
    }

    for(int i=n-1;i>0;i--){
        if(s[i]=='L' && s[i-1]=='L'){
            ans[i-2]+=ans[i];
            ans[i]=0;
        }
    }
    rep(i,n) cout<<ans[i]<<" ";
    cout<<endl;

}


Measured memory_bytes: 3864
import sys
s = input()
N = len(s)


for i in range(N-2+1):
    if s[i] == s[i+1]:
        print(i+1, i+2)
        sys.exit()

        
for i in range(N-3+1):
    if s[i] == s[i+2]:
        print(i+1, i+3)
        sys.exit()

        
        
print(-1, -1)

Measured memory_bytes: 3188
/*
 * =template=.cpp
 * Copyright (C) 2017 hzw <hzw@huzhenweideMacBook.local>
 *
 * Distributed under terms of the MIT license.
 */

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<sstream>
#include<unordered_map>
#define FR first
#define SC second
#define MP make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
inline int pow(int a,int b,int c)
{
    if (a==0)return 0;
	b=(b%(c-1)+c-1)%(c-1);
	int d=1;
    while (b)
    {
        if (b&1) d=(1LL*d*a)%c;
        a=1LL*a*a%c;b>>=1;
    }
    return d;
}
inline void read(int &x)
{
	char ch;
	while ((ch=getchar())<=32);
	x=ch-48;
	while ((ch=getchar())>32) x=x*10+ch-48;
}
inline int random(int n) { return 1LL*rand()*rand()%n+1;}
//-------------template------------
const int N=200010,M=600000,p=1000000007,inf=100000000;
const int inv2=(p+1)/2;
inline void up(int &x,int y) { x+=y;if (x>=p) x-=p;if (x<0) x+=p;}
struct Edge{int y,ne;};
int n;
int f[N];
//void add(int x,int y) { e[++num]=(Edge){y,last[x]};last[x]=num;}
int main()
{
	scanf("%d",&n);
	int ans=0;
	for (int i=1;i<=n;i++)
	{
		int x;scanf("%d",&x);
		if (x>1&&f[x-1]) f[x]=f[x-1]+1;
		else f[x]=1;
		ans=max(ans,f[x]);
	}
	printf("%d\n",n-ans);
	return 0;
}


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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
// const ll INF = 1e18;
const int INF = 1001001001;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  int D;
  ll G;
  cin >> D >> G;
  G /= 100;
  vector<int> p(D);
  vector<int> c(D);
  for (int i = 0; i < D; i++) {
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  dump(D, G);
  dumpv(p);
  dumpv(c);
  int ans = INF;
  vector<int> b(D + 1);
  while (b[D] == 0) { // until overflow
    int cnt = 0;
    int scr = 0;
    for (int i = 0; i < D; i++) {
      if (b[i]) { // solve all
        cnt += p[i];
        scr += p[i] * (i + 1) + c[i];
      }
    }
    for (int i = D - 1; 0 <= i; i--) {
      if (!b[i] && 0 < G - scr) { // solve partial
        int n = (G - scr + i) / (i + 1);
        n = min(n, p[i]);
        cnt += n;
        scr += n * (i + 1);
        break;
      }
    }
    dumpv(cnt, scr, b);
    if (G <= scr)
      ans = min(ans, cnt);
    // count b list
    for (int j = 0; j < D + 1; j++) {
      if (b[j] < 1) {
        b[j]++;
        break;
      } else {
        b[j] = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<int, int> P;
typedef pair<P, int> E;
int main() {
	int L;
	cin >> L;
	int r = 0;
	int x = 1;
	while (x * 2 <= L) {
		x *= 2;
		r++;
	}
	vector<E> ans;
	for (int i = 0; i < r; i++) {
		ans.emplace_back(P(i, i + 1), 0);
		ans.emplace_back(P(i, i + 1), 1 << i);
	}
	for (int i = r - 1; i >= 0; i--) {
		if (L - (1 << i) >= (1 << r)) {
			ans.emplace_back(P(i, r), L - (1 << i));
			L -= (1 << i);
		}
	}
	cout << (r + 1) << " " << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i].first.first + 1 << " " << ans[i].first.second + 1 << " " << ans[i].second << endl;
	}
}


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

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

std::string s[110];
int n, l;

int main() {
    read(n), read(l);
    for (int i = 1; i <= n; ++i)    std::cin >> s[i];
    std::sort(s + 1, s + n + 1);
    for (int i = 1; i <= n; ++i)    std::cout << s[i];
    puts("");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 2010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
string ans = "";
void come(ll sx,ll sy,ll gx,ll gy){
    if (sx > gx){
        while(sx != gx){
            ans += "L";
            sx--;
        }
    }
    else{
        while(sx != gx){
            ans += "R";
            sx++;
        }
    }
    if (sy > gy){
        while(sy != gy){
            ans += "D";
            sy--;
        }
    }
    else{
        while(sy != gy){
            ans += "U";
            sy++;
        }
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    come(sx,sy,tx,ty);
    come(tx,ty,sx,sy);
    ans += "D";
    come(sx,sy-1,tx+1,ty);
    ans += "L";
    ans += "U";
    come(tx,ty+1,sx-1,sy);
    ans += "R";
    PRINT(ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr int nC2(int n) { return n * (n - 1) / 2; }

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    map<int, int> counter;
    for (auto &&i : a) {
        counter[i]++;
    }

    int all = 0;
    for (auto &&i : counter) {
        all += nC2(i.second);
    }

    for (auto &&i : a) {
        int ans = all - nC2(counter[i]) + nC2(counter[i] - 1);
        cout << ans << endl;
    }
}


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

int main() {
	int n; cin >> n;
	map<int, int> mp;
	for(int i = 0; i < n; ++i) {
		int a; cin >> a;
		mp[a]++;
	}
	if(mp.size() == 1) {
		if(mp[n - 1] == n or n >= 2 * (*mp.begin()).first) {
			cout << "Yes" << '\n';
		} else {
			cout << "No" << '\n';
		}
		return 0;
	}
	if(mp.size() == 2) {
		auto itr1 = mp.begin();
		auto itr2 = next(itr1);
		int x, cntx;
		tie(x, cntx) = *itr1;
		int y, cnty;
		tie(y, cnty) = *itr2;
		if(abs(x - y) == 1) {
			if(cntx < y and 2 * (y - cntx) <= cnty) {
				cout << "Yes" << '\n';
				return 0;
			}
		} 
		cout << "No" << '\n';
		return 0;
	}
	cout << "No" << '\n';
	return 0;
}

Measured memory_bytes: 4992
s = input()

str_list = list(s)
count =0

for i in range(1,len(s)):
    if str_list[i-1] == str_list[i] == '0':
        str_list[i] = '1'
        count += 1
    elif str_list[i-1] == str_list[i] == '1':
        str_list[i] = '0'
        count += 1

print(count)

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

using ll = long long;
using namespace std;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define YES(f) if((f)){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(f) if((f)){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)

#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);

#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}


void init();
void solve();

signed main()
{
	init();
	solve();
}

void init()
{
	int N, M;
	cin >> N >> M;
	vector<int> v(M, 0);
	rep(i, N) {
		int K;
		cin >> K;
		rep(i, K) {
			int t;
			cin >> t;
			t--;
			v[t]++;
		}
	}
	int res = 0;
	rep(i, M) {
		if (v[i] == N) res++;
	}
	cout << res << endl;
}

void solve()
{
}




Measured memory_bytes: 256
/*
  author : Anand
*/

#include <bits/stdc++.h>

using namespace std;

#define PI 3.1415926535897932384626
#define int long long
#define ll long long

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string) s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

// #define LOCAL

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int INF = 1e18 + 5;
const int MOD = 1000000007;


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

	int s, w;
	cin >> s >> w;
	if ( w >= s) {
		cout << "unsafe\n";
	} else {
		cout << "safe\n";
	}

	return 0;
}

Measured memory_bytes: 3652
import scala.io.StdIn.readLine

object Main {

  def main(args: Array[String]) = {
      var n = readLine.split(" ").map(_.toInt)
      while( n(0)!= 0 || n(1) != 0) {

          if(n(0)<n(1)) println(n(0)+" "+n(1))
          else println(n(1)+" "+n(0))
          n = readLine.split(" ").map(_.toInt)
      }
  }
}

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

int n,ans=0;
int a[100005];

signed main()
{
	cin>>n;
	n+=2;
	for (int i=2;i<=n-1;i++)  cin>>a[i];
	
	for (int i=1;i<=n-1;i++)  ans+=abs(a[i+1]-a[i]);
	for (int i=2;i<=n-1;i++)  cout<<ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1])<<endl;
	
	return 0; 
} 

Measured memory_bytes: 2048
#include <cstdio>
#include <iostream>

using namespace std;

int main(){
  long W,H,x,y;
  double S;
  cin >> W >> H >> x >> y;
  S =(double)W*(double)H/(double)2; //Sは切り分けた面積の最大値
  printf("%18.10lf " ,S);
  if(W%2 == 0 && H%2 == 0){
    if(W/2 == x && H/2 == y){
      printf("1\n");
      return 0;
    }
  }
  printf("0\n");
  return 0;
  
}

Measured memory_bytes: 256
program test
implicit none
integer(8) :: i,j,k,a,b,c,ans=0

read(*,*) k

do a=1,k
  do b=1,k
    do c=1,k
      ans = ans + gcd(gcd(a,b),c)
    enddo
  enddo
enddo

write(*,*) ans

contains
integer(8) function gcd(a,b)
  implicit none
  integer(8), intent(in) :: a,b
  integer(8) :: l,m,n

  m = a
  n = b

  do
    l = mod(m,n)
    if (l == 0) exit
    m = n
    n = l
  end do

  gcd = n

  return
end function gcd

end program

Measured memory_bytes: 2700
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int H,W;
	scanf("%d %d",&H,&W);

	char** map = new char*[H];
	for(int i = 0; i < H; i++)map[i] = new char[W+1];

	for(int i = 0; i < H; i++)scanf("%s",map[i]);

	char emblem[2][3];
	scanf("%s",emblem[0]);
	scanf("%s",emblem[1]);

	int base = 0;

	for(int row = 0; row < H-1; row++){
		for(int col = 0; col < W-1; col++){
			if(map[row][col] == emblem[0][0] && map[row][col+1] == emblem[0][1] &&
					map[row+1][col] == emblem[1][0] && map[row+1][col+1] == emblem[1][1])base++;
		}
	}

	int max_add = 0,pre_num,tmp_num;
	char pre_char,array[4] = "JOI";

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){

			pre_char = map[row][col];

			pre_num = 0;

			if(row-1 >= 0 && col-1 >= 0){
				if(map[row-1][col-1] == emblem[0][0] && map[row-1][col] == emblem[0][1] &&
						map[row][col-1] == emblem[1][0] && map[row][col] == emblem[1][1])pre_num++;
			}

			if(row-1 >= 0 && col+1 <= W-1){
				if(map[row-1][col] == emblem[0][0] && map[row-1][col+1] == emblem[0][1] &&
										map[row][col] == emblem[1][0] && map[row][col+1] == emblem[1][1])pre_num++;
			}

			if(row+1 <= H-1 && col-1 >= 0){
				if(map[row][col-1] == emblem[0][0] && map[row][col] == emblem[0][1] &&
							map[row+1][col-1] == emblem[1][0] && map[row+1][col] == emblem[1][1])pre_num++;
			}

			if(row+1 <= H-1 && col+1 <= W-1){
				if(map[row][col] == emblem[0][0] && map[row][col+1] == emblem[0][1] &&
							map[row+1][col] == emblem[1][0] && map[row+1][col+1] == emblem[1][1])pre_num++;
			}

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

				map[row][col] = array[i];

				tmp_num = 0;

				if(row-1 >= 0 && col-1 >= 0){
					if(map[row-1][col-1] == emblem[0][0] && map[row-1][col] == emblem[0][1] &&
							map[row][col-1] == emblem[1][0] && map[row][col] == emblem[1][1])tmp_num++;
				}

				if(row-1 >= 0 && col+1 <= W-1){
					if(map[row-1][col] == emblem[0][0] && map[row-1][col+1] == emblem[0][1] &&
											map[row][col] == emblem[1][0] && map[row][col+1] == emblem[1][1])tmp_num++;
				}

				if(row+1 <= H-1 && col-1 >= 0){
					if(map[row][col-1] == emblem[0][0] && map[row][col] == emblem[0][1] &&
								map[row+1][col-1] == emblem[1][0] && map[row+1][col] == emblem[1][1])tmp_num++;
				}

				if(row+1 <= H-1 && col+1 <= W-1){
					if(map[row][col] == emblem[0][0] && map[row][col+1] == emblem[0][1] &&
								map[row+1][col] == emblem[1][0] && map[row+1][col+1] == emblem[1][1])tmp_num++;
				}

				max_add = max(max_add,tmp_num-pre_num);

			}

			map[row][col] = pre_char;
		}
	}


	printf("%d\n",base+max_add);

	return 0;
}

Measured memory_bytes: 4236
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
typedef long long ll;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	int n;
	cin >> n;
	int ans = 0;
	int a[n];
	for(int i=1; i<n; i++){
		cin >> a[i];
	}
	a[0] = a[1];
	a[n-1] = a[n-1];
	for(int i=1; i<n-1; i++){
		a[i] = min(a[i], a[i+1]);
	}
	int sum = 0;
	for(int i=0; i<n; i++) sum += a[i];
	cout << sum <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <iomanip>
#include <functional>
#include <array>
#include <climits>
#include <cmath>

using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;

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

    typedef map<ll, ll> dmap;
    dmap drink;
    for (int i = 0; i < N; i++)
    {
        ll a, b;
        cin >> a >> b;
        if (drink.find(a) == drink.end())
        {
            drink.insert(make_pair(a, b));
        }
        else
        {
            drink[a] += b;
        }
    }
    ll ans = 0;
    for (dmap::iterator it = drink.begin(); it != drink.end(); ++it)
    {
        ll a = it->first;
        ll b = it->second;
        if (b > M)
        {
            b = M;
        }
        ans += a * b;
        M -= b;
        if (M <= 0)
        {
            break;
        }
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
#define int ll
#define sz(x) (ll)x.size()
using namespace std;
 
 
const ll MOD = 998244353;
const ll INF = 1e9;
const ll LOG = 29;
#define PI 3.141592653589793238 
 
 
 


const ll N =(5e5+5);

ll fact[N];

long long binpow(long long a, long long b) {
     a%=MOD;    
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD;
        a = (a * a)%MOD;
 
        
        b >>= 1;
    }
     res%=MOD;
    return res;
}
void ini(){
    fact[0] = 1;
    for(int i = 1;i < N;i++){
        fact[i] = (fact[i-1] * i)%MOD;
    }
}
ll ncr(ll n,ll r){
    ll ret = fact[n];
    ret = (ret * binpow(fact[r],MOD-2))%MOD;
    ret = (ret * binpow(fact[n-r],MOD-2))%MOD;
    return ret;
}

void solve(){
    ll x,y;
    cin >> x >> y;
    ll ans = 0;
    if(x == 3){
        ans += 1e5; 
    }
    else if(x == 2){
        ans += 2e5;
    }
    else if(x == 1)
        ans += 3e5;


    if(y == 3){
        ans += 1e5; 
    }
    else if(y == 2){
        ans += 2e5;
    }
    else if(y == 1)
        ans += 3e5;
    if(x == 1 && y == 1){
        ans += 4e5;
    }
    cout << ans << endl;





}   
/*
5
abcab
aabab

aabbc
aaabb

*/

 
   
 
 
 /*
 2 3 4 5 6 1
 3 6 10 15 21 
 4 10 20 35 56 
 5 15 35 70 126 
 6 21 56 126 252 
*/
 
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
       
 
     ll tt=1;
    while(tt--){
        solve();
    }    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

void Solution()
{
	int N;
	int a[100] = {0};
	int count = 0;

	cin>>N;

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

	for (int i = 0; i < N - 1; i++)
	{
		for (int j = 1; j < N - i; j++) // leave out the last digit
		{
			if (a[j - 1] > a[j])
			{
				swap(a[j - 1], a[j]);
				count++;
			}
		}
	}

	for(int i  = 0; i < N - 1; i++)
	{
		cout<<a[i]<<" ";
	}
	cout<<a[N - 1]<<endl;
    cout<<count<<endl;


}

int main()
{
	Solution();
	return 0;
}

Measured memory_bytes: 1160
N = int(input())
ans = [0,0,0,0]
for _ in range(N):
    a = input()
    if a == 'AC':
        ans[0] += 1
    elif a == 'WA':
        ans[1] += 1
    elif a == 'TLE':
        ans[2] += 1
    elif a == 'RE':
        ans[3] += 1
print('AC x',ans[0])
print('WA x',ans[1])
print('TLE x',ans[2])
print('RE x',ans[3])


Measured memory_bytes: 9204
n,m = map(int,input().split())
l = list(map(int,input().split()))

ans = 0
for i in range(m):
    ans += l[i]
a = ans
for i in range(m,n):
    a = a+l[i]-l[i-m]
    if a > ans:
        ans = a
print((ans+m)/2)




Measured memory_bytes: 25060
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
string h1,h2,h3;
int main(int argc, const char * argv[]) {
   
    cin >> h1;
    cin >> h2;
    cin >> h3;
    
    cout << h1[0] << h2[1] <<h3[2];
    
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=1000000007LL;
const ll MOD=998244353LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};

int main(){
  ll n;cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  map<ll,ll>M;
  rep(i,n)M[a[i]]++;
  if(M.size()==1){
    if((M[a.front()]>=a.front()*2)||(M[a.front()]==a.front()+1)){
      cout<<"Yes"<<endl;
      //cout<<"ok"<<endl;
      return 0;
    }
  }
  else if(a.back()-a.front()==1){
    if(M[a.front()]<=a.front()&&M[a.back()]>=(a.back()-M[a.front()])*2){
      cout<<"Yes"<<endl;
      return 0;
    }

  }
  cout<<"No"<<endl;
}

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

#define int long long

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

	int q;
	cin >> q;
	int ff = 0;
	deque<char> que;
	for(int i = 0;i < s.size();i++) que.push_back(s[i]);
	while(q--){
		int t;
		cin >> t;
		if(t == 1){
			ff ^= 1;
		}else{
			int f;
			char c;
			cin >> f >> c;
			f--;
			f ^= ff;
			if(f == 0){
				que.push_front(c);
			}else{
				que.push_back(c);
			}
		}
	}

	while(!que.empty()){
		if(ff == 0){
			cout << que.front();
			que.pop_front();
		}else{
			cout << que.back();
			que.pop_back();
		}
	}
	cout << endl;

	return 0;
}


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

 
int main() {
   int k,x;
   cin>>k>>x;
   for(int i=x-k+1;i<=x+k-1;i++)cout<<i<<" ";
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int Bsort(int A[],int N){
  int x=0;
  bool flag=1;
  for(int i=0;flag;i++)
    {
      flag=0;
      for(int j=N-1;j>=i+1;j--)
        {
          if(A[j]<A[j-1])
            {
              swap(A[j],A[j-1]);
              flag=1;
              x++;
            }
        }
    }
  return x;
}

int main(){
  int A[100],N,x;
  cin>>N;
  for(int i=0;i<N;i++)cin>>A[i];
  x=Bsort(A,N);
  for(int i=0;i<N;i++)
    {
      if(i)cout<<" ";
      cout<<A[i];
    }
  cout<<endl;
  cout<<x<<endl;
  return 0;
}



Measured memory_bytes: 3092