akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int a[3][3];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j< 3; j++){
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;

    int tmp;
    bool mark[3][3] = {};
    for(int i = 0; i < n; i++){
        cin >> tmp;
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(tmp == a[j][k]){
                    mark[j][k] = true;
                }
            }
        }
    }

    string ans = "No";
    for(int i = 0; i < 3; i++){
        if(mark[i][0] and mark[i][1] and mark[i][2]){
            ans = "Yes";
        }
    }
    for(int i = 0; i < 3; i++){
        if(mark[0][i] and mark[1][i] and mark[2][i]){
            ans = "Yes";
        }
    }
    if(mark[0][0] and mark[1][1] and mark[2][2]){
        ans = "Yes";
    }
    if(mark[0][2] and mark[1][1] and mark[2][0]){
        ans = "Yes";
    }

    cout << ans << endl;
}

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

using namespace std;

const int inf = 99999999;

int func(int a[4])
{
	int t=0;
	
	for(int i = 0; i < 3; i++){
		t += ((a[i+1]-a[i])*(a[i+1]-a[i]));
	}
	
	return t;
}

int main()
{
	int n, m;
	
	while(cin>>n>>m && n && m){
		vector<int> vn, vm;
		
		for(int i = 1; i <= n; i++){
			if(n%i == 0){
				vn.push_back(i);
			}
		}
		for(int i = 1; i <= m; i++){
			if(m%i == 0){
				vm.push_back(i);
			}
		}
		int s = inf;
		for(int i = 0; i < vn.size(); i++){
			for(int j = 0; j < vm.size(); j++){
				int a[4];
				a[0] = vn[i];
				a[1] = n/vn[i];
				a[2] = vm[j];
				a[3] = m/vm[j];
				sort(a, a+4);
				s = min(s, func(a));
			}
		}
		
		cout << s << endl;
	}
	
	return 0;
}

Measured memory_bytes: 908
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


void Main(){
    ll Q, H, S, D, N;
    cin >> Q >> H >> S >> D;
    cin >> N;
    chmin(H, Q*2);
    chmin(S, H*2);
    chmin(D, S*2);
    cout << (N/2)*D + (N%2)*S << el;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in n;
VVI impl;
VI fl;
VI x,y;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in m;
  cin>>n>>m;
  fl.resize(n);
  impl.resize(n,VI(n,0));
  forn(i,n)
    impl[i][i]=1;
  x.resize(m);
  y.resize(m);
  forn(i,m){
    cin>>x[i]>>y[i];
    --x[i];
    --y[i];
  }
  reverse(all(x));
  reverse(all(y));
  in a,b;
  forn(i,n){
    VI& v=impl[i];
    forn(j,m){
      a=x[j];
      b=y[j];
      if(v[a]&&v[b]){
	fl[i]=1;
      }
      if(v[a])
	v[b]=1;
      if(v[b])
	v[a]=1;
    }
  }
  in sm=0;
  forn(i,n){
    forn(j,i){
      if(fl[i]||fl[j])
	continue;
      bool ok=1;
      forn(k,n){
	if(impl[i][k] && impl[j][k])
	  ok=0;
      }
      sm+=ok;
    }
  }
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
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; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  int ans=0;
  if(a<0){
    ans+=(0-a)*c+d;
    ans+=b*e;
  }
  else if(a==0){
    ans+=ans+=(b-a)*e+d;
  }
  else{
    ans+=(b-a)*e;
  }
  
  cout << ans << endl;
}



Measured memory_bytes: 3184
# 累積和をととっといて比較
n = int(input())
arr = list(map(int, input().split()))

ruiseki = [0 for _ in range(n)]
ruiseki[0] = arr[0]

for i in range(1, n):
    ruiseki[i] += ruiseki[i - 1] + arr[i]

inf = 10 ** 20
ans = inf

for i in range(n - 1):
    x = ruiseki[i]
    y = ruiseki[-1] - x
    ans = min(ans, abs(x - y))
print(ans)


Measured memory_bytes: 86736
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<utility>
#include<vector>
#include<climits>
#include<queue>
#include<random>
#include<map>

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

int n,mm;


int main(int argc, char const *argv[]) {

    cin >> n >> mm;
    vector<int> k(n);
    for(int i=0;i<n;i++) cin >> k[i];
    map<ll , int> m;
    vector<int> sum(n+1);
    sum[0] = 0;
    for(int i=0;i<n;i++){
        sum[i+1] = (sum[i] + k[i])%mm;
    }

    ll ans=0;

    for(int i=0;i<=n;i++){
        ans += m[sum[i]];
        m[sum[i]]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
N=int(input())
x=[]
u=[]
for n in range(N):
  X,U=input().split()
  if "." in X:
    X=float(X)
  else:
    X=int(X)
  x.append(X)
  u.append(U)
s=[]
for i in range(N):
  if u[i]=="JPY":
    s.append(x[i])
  elif u[i]=="BTC":
    s.append(x[i]*380000.0)
print(sum(s))

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m;
vector<pii> g[125252];
unordered_map<int,int> typedeg[125252];
unordered_set<int> visited[125252];
int dist[125252];
 
int main(){
  scanf("%d%d",&n,&m);
  REP(i,m){
    int p,q,c;
    scanf("%d%d%d",&p,&q,&c);
    --p;--q;
    g[p].push_back(pii(q,c));
    g[q].push_back(pii(p,c));
    typedeg[p][c] += 1;
    typedeg[q][c] += 1;
  }
  // -dist,pos,type
  deque<pair<int,pii>> Q;
  const int INF = 830252521;
  REP(i,n)dist[i]=INF;
  dist[0] = 0;
  Q.push_back(make_pair(0,pii(0,-1)));
  bool sd = false;
  while(!Q.empty()){
    pair<int,pii> P = Q.front(); Q.pop_front();
    int d = P.first;
    int pos = P.second.first;
    int type = P.second.second;
    for(const pii& T:g[pos]){
      int to = T.first;
      if(to==0)continue;
      int totype = T.second;
      int cost = type==totype ? 0 : 1;
      int ndist = d + cost;
      if(sd){
        if(ndist > dist[n-1])continue;
      }
      if(ndist > dist[to])continue;
      else if(ndist == dist[to]){
        if(to!=n-1){
          if(visited[to].count(totype) || typedeg[to][totype]==1)continue;
        }
      }else{
        visited[to].clear();
        visited[to].insert(totype);
        dist[to] = ndist;
      }
      // go
      visited[to].insert(totype);
      if(to==n-1){
        if(cost==0){
          Q.clear();
          break;
        }else{
          sd = true;
        }
      }else{
        if(cost==0){
          Q.push_front(make_pair(ndist,pii(to,totype)));
        }else{
          Q.push_back(make_pair(ndist,pii(to,totype)));
        }
      }
    }
  }
  if(dist[n-1]==INF){
    puts("-1");
    return 0;
  }
  // ans = dist[n-1] or dist[n-1]-1 (because of train company)
  int ans = dist[n-1];
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 47616
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val numbers = readLine()!!.split(" ").map { it.toInt() }
    val sum = numbers.reduce{ a,b -> a + b}
    numbers.forEach {
        if (it >= sum - it) {
            return println("No")
        }
    }
    println("Yes")
}


Measured memory_bytes: 35976
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Dice dice = new Dice(sc.nextInt(),
                             sc.nextInt(),
                             sc.nextInt(),
                             sc.nextInt(),
                             sc.nextInt(),
                             sc.nextInt());

        int q = sc.nextInt();
        while (q-- > 0) {
            int top = sc.nextInt();
            int south = sc.nextInt();
            System.out.println(eastFace(dice, top, south));
         }
    }
    private static int eastFace(Dice d, int top, int south) {
        int i = 0;
        int m = 6;
        while (m-- > 0) {
            if (d.getTop() == top) {
                int n = 4;
                while (n-- > 0) {
                    if (d.getSouth() == south)
                        return d.getEast();
                    d = roll(d, "NES");
                }
                assert false; // invalid input
            }
            assert i < 6;
            d = roll(d, "NNWNN".charAt(i++));
        }
        assert false;
        return -1;
    }
    private static Dice roll(Dice d, String directions) {
        for (int i = 0; i < directions.length(); i++)
            d = roll(d, directions.charAt(i));
        return d;
    }
    private static Dice roll(Dice d, int direction) {
        switch (direction) {
        case 'N': return d.rollToN();
        case 'S': return d.rollToS();
        case 'W': return d.rollToW();
        case 'E': return d.rollToE();
        }
        assert false;
        return null;
    }

    private static class Dice {
        private int t;
        private int s;
        private int e;
        private int w;
        private int n;
        private int b;

        public Dice() {
            this(1, 2, 3, 4, 5, 6);
        }
        public Dice(int t, int s, int e, int w, int n, int b) {
            this.t = t;
            this.s = s;
            this.e = e;
            this.w = w;
            this.n = n;
            this.b = b;
        }
        public Dice rollToN() {
            return new Dice(s, b, e, w, t, n);
        }
        public Dice rollToS() {
            return new Dice(n, t, e, w, b, s);
        }
        public Dice rollToW() {
            return new Dice(e, s, b, t, n, w);
        }
        public Dice rollToE() {
            return new Dice(w, s, t, b, n, e);
        }
        public int getTop() {
            return t;
        }
        public int getSouth() {
            return s;
        }
        public int getEast() {
            return e;
        }
    }
}



Measured memory_bytes: 26280
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var result = -1;
            var a = 7;

            for(int i = 0; i < k; i++)
            {
                if (a % k == 0)
                {
                    result = i + 1;
                    break;
                }
                else
                    a = 10 * (a % k) + 7;
            }
            Console.WriteLine(result);
        }    
    }
}


Measured memory_bytes: 27540
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  vector<int> p(5,0);
  for(int i=0;i<6;++i){
    cin>>n;
    p[n]++;
  }
  for(int i=1;i<=4;++i){
    if(p[i]==0||p[i]==3){
      cout<<"NO";
      return 0;
    }
  }
  cout<<"YES";
  return 0;
}

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

int main()
{
    long n, k; cin>>n>>k;
    vector<long> a(n);
    for(auto& e: a) cin>>e;

    long res=0;
    ++k;
    for(long i; i=k&-k; k-=i) {
        long x=k-i;
        for(int j=0; (1L<<j)<i; ++j) {
            int c=0;
            for(auto& e: a) c+=(e>>j)&1;
            if (2*c<n) x|=1L<<j;
        }
        long s=0;
        for(auto& e: a) s+=x^e;
        if (res<s) res=s;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdio>
#include <climits>
using namespace std;

int main(void){
    long long N,M,K;

    cin >> N >> M >> K;

    long long A[N + 1];
    long long B[M + 1];
    A[0] = 0;
    for (long i = 1; i <= N; ++i)
    {
        cin >> A[i];
        A[i] = A[i] + A[i-1];
    }
    B[0] = 0;
    for (long i = 1; i <= M; ++i)
    {
        cin >> B[i];
        B[i] = B[i] + B[i-1];
    }

    long books = 0;
    long j = M;

    for (long i = 0; i <= N; i++){
        if (A[i] > K){
            break;
        }
        while (B[j] > K - A[i]){
            j--;
        }
        books = max(books, (i + j));
    }
    cout << books << "\n";
}


Measured memory_bytes: 6276
import math

def is_int_num(num):
  if isinstance(num, int):
    return True
  if isinstance(num, float):
    return num.is_integer()
  return False

def calc_dist(A,B):
  n=0
  for (a, b) in zip(A,B):
    n+=(a-b)**2
  return math.sqrt(n)

N,D=map(int, input().split())
mylist=list(list(map(int, input().split())) for n in range(N))
count=0
for i in range(N-1):
  for j in range(i+1,N):
    dist=calc_dist(mylist[i],mylist[j])
    if is_int_num(dist):
      count+=1
print(count)

Measured memory_bytes: 3188
#include <iostream>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < n; i++)
 
int main(void) {
    string s;
    cin >> s;
    int ans = 0; // 数を数えるための変数。これが答えになる
    
    if (s[0] == '1') {ans++;}
    if (s[1] == '1') {ans++;}
    if (s[2] == '1') {ans++;}
  
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String str = sc.nextLine();
        char[]  c= new char[str.length()];
        for(int i=0;i<str.length();i++){

            c[i] = str.charAt(i);
            if(Character.isLowerCase(c[i])){
                c[i]=Character.toUpperCase(c[i]);
            }
            else if(Character.isUpperCase(c[i])){
                c[i]=Character.toLowerCase(c[i]);
            }
        }
        for(int i=0;i<str.length();i++){
            System.out.print(c[i]);
        }
        System.out.println();

    }
}


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

int main(){

    string s; cin >> s;
    int k; cin >> k;
    set<string> S;

    for(int i = 0; i < k; i++){
        string tmp = "zzzzzzzzzzzzzzzz";

        for(int j = 0; j < (int)s.size(); j++){
            for(int l = j; l <= j + 5; l++){
                if(l == (int)s.size()) break;

                string t;
                for(int o = j; o <= l; o++){
                    t += s[o];
                }

                if(tmp > t && S.find(t) == S.end()) tmp = t;

            }
        }

        if(i == k - 1){
            cout << tmp << endl;
            break;
        }
        S.insert(tmp);
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

class FordFulkerson:
    def __init__(self, n):
        self.N = n
        self.G = [[] for _ in range(n)]
        
    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)
        
    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)
    
    def dfs(self, v, t, f):
        if v == t:
            return f
        used = self.used
        used[v] = 1
        for e in self.G[v]:
            w, cap, rev = e
            if cap and not used[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0
    

    def flow(self, s, t):
        flow = 0
        f = INF = 10**9 + 7
        N = self.N
        while f:
            self.used = [0]*N
            f = self.dfs(s, t, INF)
            flow += f
        return flow
    
def main():
    n = int(input())
    red = [list(map(int, input().split())) for _ in range(n)]
    blue = [list(map(int, input().split())) for _ in range(n)]
    
    flow = FordFulkerson(n*2+2)
    for i in range(n):
        flow.add_edge(0, i+1, 1)
        flow.add_edge(n+i+1, 2*n+1, 1)
        for j in range(n):
            if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
                flow.add_edge(i+1, n+j+1, 1)
    
    
    ans = flow.flow(0, 2*n+1)
    print(ans)
    
if __name__ == "__main__":
    main()


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

#define pb push_back

//var 
int n,m,t1,t2,dp[100001],ans = 0;
vector<int> e[100001];
bool v[100001];

void dfs(int g){
	dp[g] = 1; int am = 0;
	v[g] = 1;
	for(int u : e[g]){
		if(!v[u])dfs(u);
		am = max(am,dp[u]);
	}dp[g] += am;
}

int main(){
	cin >> n >> m;
	for(int i = 1; i<=m; i++){
		cin >> t1 >> t2;
		e[t1].pb(t2);
	}

	for(int i = 1; i<=n; i++){
		if(!v[i])dfs(i); ans = max(ans,dp[i]);
	}cout << --ans << endl;
}

Measured memory_bytes: 8192
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;  // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

ll powll(ll p, ll n) {
    ll ret = 1;
    rep(i, 0, n) {
        ret *= p;
    }
    return ret;
}

int main() {
    ll n, p;
    cin >> n >> p;

    // value - count
    vector<pair<ll, ll>> pfVec = prime_factorize(p);

    ll ans = 1;
    for (pair<ll, ll> val : pfVec) {
        // cout << val.first << ":" << val.second << ":" << val.second / n << endl;
        ans *= powll(val.first, val.second / n);
    }

    std::cout << ans << endl;

    return 0;
}


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

// バケット法

int main(void){
    int n;
    cin >> n;
    vector<int> d(110);
    vector<int> vec(110);
    rep(i,n) cin >> d.at(i);

    rep(i,n){
        vec.at(d.at(i))++;
    }
    int res = 0;
    rep(i,110){
        if(vec.at(i) > 0){
            res++;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int INF = 1e9 +7;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i , n){
        cin >> a[i];
    }

    int count2 = 0;
    int count4 = 0;
    REP(i, n){
        if(a[i] % 4 == 0){
            count4++;
        }else{
            if(a[i] % 2 == 0){
                count2++;
            }
        }
    }

    count2 = count2/2 * 2;
    if(count2 * 2 + count4 * 4 >= n/2 * 4){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1000000000;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m+1);
    vector<int> C(m+1);
    ll cost = 0;
    ll open = 0;
    for(int i = 1;i <= m;i++){
        int b;
        cin >> a[i] >> b;
        int c;
        for(int j = 0;j < b;j++){
            cin >> c;
            C[i] |= (1 << c-1);
        }
    }
    int MAX = 1;
    MAX <<= n;
    vector<vector<int>> dp(m+1,vector<int>(MAX,INF));
    for(int i = 0;i <= m;i++)dp[i][0] = 0;
    for(int i = 1;i <= m;i++){
        for(int j = 0;j < (1 << n);j++){
            dp[i][j] = min(dp[i][j],dp[i-1][j]);
        }
        for(int j = 0;j < (1 << n);j++){
            int x = (j | C[i]);
            dp[i][x] = min(dp[i][x], dp[i][j] + a[i]);
        }
    }
    /*for(int i = 0;i < MAX;i++){
        for(int j = 0;j <= m;j++){
            cout << setw(10) << setfill('0') << dp[j][i] << " ";
        }
        cout << endl;
    }*/
    if(dp[m][MAX-1] == INF)cout << -1 << endl;
    else cout << dp[m][MAX-1] << endl;
    //cin >> n;
}

Measured memory_bytes: 16384
x,y = map(int,input().split())
if abs(x)<=abs(y):
    count = 0
    if x <0:
        count += 1
    if y <0:
        count += 1
    count += abs(y)-abs(x)
    print(count)
else:
    if x <=0:
        a = y -x
        b = abs(x)-abs(y)+1
        print(min(a,b))
    else:
        a = 1 + (y+x)
        b = 1 + abs(x) - abs(y)
        if y > 0:
            b+= 1
        print(min(a,b))

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:
int n;
const int limit = 310;
ll a[limit][limit];
ll d[limit][limit];


int main(void){
	cin >> n;
	rep(i,n)rep(j,n) cin >> a[i][j];

	rep(i,n)rep(j,n) d[i][j]=a[i][j];

	rep(k,n)rep(i,n)rep(j,n) chmin(d[i][j],d[i][k]+d[k][j]);

	bool ok = true;
	rep(i,n)rep(j,n) if(a[i][j]!=d[i][j]) ok=false;

	if(ok==false){
		puts("-1");
		return 0;
	}

	ll ans = 0LL;
	rep(i,n)rep(j,n) ans+=d[i][j];
	rep(i,n)rep(j,n){
		bool cut = false;
		rep(k,n) if(k!=i and k!=j and d[i][j]==d[i][k]+d[k][j]) cut = true;
		if(cut) ans-=d[i][j];
	} 

	cout << ans/2 << endl;

	return 0;
}

Measured memory_bytes: 1664
N,M =map(int,input().split( ))
X = list(map(int,input().split( )))


if N >= M or M == 1:
	ans = 0
elif N == 1:
	X.sort()
	ans = X[-1] -X[0]
else:
	X.sort()
	D = []
	for i in range(M-1):
		d = X[i+1] - X[i]
		D.append([i,d])
	#print(X)

	D.sort(key = lambda x:(x[1]),reverse =True)
	#print(D)
	sikiri = []
	for i in range(N-1):
		sikiri.append(D[i][0])
	sikiri.sort()
	ans = X[sikiri[0]] - X[0]
	for i in range(N-1):
		l = sikiri[i]+1
		if i == N-2:
			r = M-1
		else:
			r = sikiri[i+1]
		ans+= X[r]-X[l]
print(ans)

Measured memory_bytes: 21584
/**
 *    author:  FromDihPout
 *    created: 2020-06-10
**/

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


const int MOD = 1e9 + 7;

int expo(int base, int e) {
    if (e == 0) {
        return 1;
    }
    else if (e & 1) {
        int half = expo(base, e / 2);
        return (int) ((long long) base * half * half % MOD);
    }
    else {
        int half = expo(base, e / 2);
        return (int) ((long long) half * half % MOD);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a[x]++;
    }
    
    if (n & 1) {
        if (a[0] != 1) {
            cout << 0 << '\n';
            return 0;
        }
        for (int i = 2; i < n; i+=2) {
            if (a[i] != 2) {
                cout << 0 << '\n';
                return 0;
            }
        }
    }
    else {
        for (int i = 1; i < n; i+=2) {
            if (a[i] != 2) {
                cout << 0 << '\n';
                return 0;
            }
        }
    }
    
    cout << expo(2, n / 2) << endl;
    return 0;
}

Measured memory_bytes: 3752
# B Battle

A, B, C, D = map(int, input().split())

t_kill_a = C // B
a_kill_t = A // D

if C % B != 0:
  t_kill_a += 1
if A % D != 0:
  a_kill_t += 1

if t_kill_a <= a_kill_t:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 8984
#include<stdio.h>
int main(void){
        int n;
        long int i,j,k,ans=0;
        long int ma[5]={};
        char str[10]={};
        char march[5]={'M','A','R','C','H'};
        scanf("%d",&n);
        for(i=0;i<n;i++){
                scanf("%s",str);
                //printf("%s\n",str);
                for(j=0;j<5;j++){
                        if(str[0]==march[j])ma[j]++;
                }
                //printf("ii=%d\n",i);
        }
        for(i=0;i<5;i++){
                for(j=i+1;j<5;j++){
                        for(k=j+1;k<5;k++){
                                ans+=ma[i]*ma[j]*ma[k];
                        }
                }
        }
        printf("%ld",ans);
        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

//matp G(N);
void graphmake(ll E,matp &G){
  rep(i,E){
    ll a,b,c;
    cin >> a >> b >> c;
    G.at(a-1).push_back(P(b-1,c));
    G.at(b-1).push_back(P(a-1,c));//有向なら消す
  }
}
//vec d(N);
void dijkstra(ll s,vec &d, matp &G,ll V){
  priority_queue<P,vector<P>,greater<P>> que;
  rep(i,V) d.at(i)=INF;
  d.at(s)=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    ll v=p.second;
    if(d.at(v)<p.first) continue;
    rep(i,G.at(v).size()){
      P e=G.at(v).at(i);
      if(d.at(e.first)>d.at(v)+e.second){
        d.at(e.first)=d.at(v)+e.second;
        que.push(P(d.at(e.first),e.first));
      }
    }
  }
}


int main(){
  ll K,N,m=0;
  cin >> K >> N;
  vec A(N);
  rep(i,N){
    cin >> A.at(i);
    if(i!=0){
      m=max(m,A.at(i)-A.at(i-1));
    }
    if(i==N-1){
      m=max(m,K+A.at(0)-A.at(i));
    }
  }
  cout << K-m << endl;
}
          
      

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

template<typename T>
T gcd(T a,T b)
{
  return b==0?a:gcd(b,a%b);
}
int main()
{
	int T; scanf("%d",&T);
	unsigned long int A,B,C,D;
	for(int i=0;i<T;i++)
	{
		scanf("%ld%ld%ld%ld",&A,&B,&C,&D);
		if(A<B || D<B || C<A%B || C<B-gcd(B,D))	puts("No");
		else		puts("Yes");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;


int main() {
	int n;
	cin >> n;
	for (int i = 0; i < 10; ++i)
	{
		for (int j = 0; j < 10; ++j)
		{
			if (i*j == n) {
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
}
 


Measured memory_bytes: 3596
#include<stdio.h>
int main(void){
	int N,quo,rem,ans=0;

	scanf("%d",&N);
	for(;;){
		quo=N/3;
		rem=N%3;
		ans++;
		if(quo==0||quo==1&&rem==0){break;}
		if(rem!=0){N=quo+1;}
		else{N=quo;}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 596
n = input()

def nine(s):
    st = ""
    for _ in range(s):
        st += "9"
    return st

if len(n) == 1:
    print(n)
    exit()

if int(n[0]) == 1:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 1)
        exit()
    else:
        print(9*(len(n) -1))
        exit()

if int(n[0]) == 2:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 2)
        exit()
    else:
        print(9*(len(n) -1) + 1)
        exit()

if int(n[0]) == 3:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 3)
        exit()
    else:
        print(9*(len(n) -1) + 2)
        exit()

if int(n[0]) == 4:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 4)
        exit()
    else:
        print(9*(len(n) -1) + 3)
        exit()

if int(n[0]) == 5:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 5)
        exit()
    else:
        print(9*(len(n) -1) + 4)
        exit()

if int(n[0]) == 6:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 6)
        exit()
    else:
        print(9*(len(n) -1) + 5)
        exit()

if int(n[0]) == 7:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 7)
        exit()
    else:
        print(9*(len(n) -1) + 6)
        exit()

if int(n[0]) == 8:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 8)
        exit()
    else:
        print(9*(len(n) -1) + 7)
        exit()

if int(n[0]) == 9:
    if int(n[1:]) >= int(nine(len(n) - 1)):
        print(9*(len(n) -1) + 9)
        exit()
    else:
        print(9*(len(n) -1) + 8)
        exit()

Measured memory_bytes: 9304
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=2e5;
const long inf=1e9;
int main(){
	int N; cin>>N;
	int a; int cnt = 0;
	rep(i,0,N){
		cin>>a;
		if(i % 2 == 0 && a % 2 == 1) cnt++;
	}cout<<cnt<<endl;
}

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

struct UnionFind{
// 同値関係をサポートするデータ構造
// 併合,所属する同値類の代表元: O(a(n)), 集合の分割はNG
// (a(n): アッカーマン関数A(m,n)について,f(n)=A(n,n)としたときの逆関数)
  vector<int> m_root;
  vector<int> m_size;
  int m_Ngroup;

  UnionFind(int N)
  : m_root(N)
  , m_size(N,1)
  , m_Ngroup(N)
  { iota(m_root.begin(), m_root.end(), 0); }

  int find(int a){
    if(m_root.at(a)==a){
      return a;
    }
    else{
      return m_root.at(a)= find(m_root.at(a));
    }
  }

  void unify(int a, int b){
    int r_a= find(a);
    int r_b= find(b);

    if(r_a != r_b){
      m_Ngroup--;
      if(m_size.at(r_a) < m_size.at(r_b)){
        m_root.at(r_a)= r_b;
        m_size.at(r_b)+= m_size.at(r_a);
        return;
      }
      else{
        m_root.at(r_b)= r_a;
        m_size.at(r_a)+= m_size.at(r_b);
        return;
      }
    }
  }
  
  bool are_comrade(int a, int b){
    return find(a)==find(b);
  }

  int get_size(){
    return m_Ngroup;
  }
  int get_size(int a){
    return m_size.at(find(a));
  }
};

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

  UnionFind uf(N);
  int buf1,buf2;
  for(int j=0; j<M; j++){
    cin >> buf1 >> buf2;
    buf1--; buf2--; // 1-indexed -> 0-indexed
    uf.unify(buf1, buf2);
  }

  int ans= uf.get_size()- 1;
  
  cout << ans << endl;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    long long int n,m,i,j,k,l,p;
    cin>>n;
    p = 100;
    j = 0;
    while(p<n)
    {
        p+=p*0.01;
        j++;
    }
    cout<<j;
}


Measured memory_bytes: 3628
/******************************************
* AUTHOR : SARTHAK GUPTA *
* NICK : SOPHOZAAR *
* INSTITUTION : BIT MESRA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

int n;
int a[N][3];

int dp[N][3];

int func(int index, int type) {

	if(index >= n) {
		return 0;
	}
	if(index == n - 1)
		return a[index][type];

	if(dp[index][type] != -1)
		return dp[index][type];
	
	int temp = 0;
	return dp[index][type] = a[index][type] + max(func(index + 1, (type + 1) % 3), func(index + 1, (type + 2) % 3));
}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);

cin >> n;
for(int i = 0; i < n; i++) {
	
	for(int j = 0; j < 3; j++) {
		cin >> a[i][j];
		dp[i][j] = -1;
	}
}

int res = max(func(0, 0), max(func(0, 1), func(0, 2)));
cout << res << "\n";

return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 998244353;
#define MAX_N 310

ll N;
vector<ll> A;

ll halfS;
ll dp1[MAX_N][MAX_N * MAX_N];
ll dp2[MAX_N][MAX_N * MAX_N];

// Ai を見ていて、現在の合計数が r のとき、
// R の合計が s/2 以上になるパターン数
ll dfs1(ll i = 0, ll r = 0) {
    if(i >= N) { return (r >= halfS) ? 1 : 0; }

    ll& ret = dp1[i][r];
    if(~ret) { return ret; }

    ret = dfs1(i + 1, r);            // Ai は青色になった
    ret %= MOD;
    ret += dfs1(i + 1, r);           // Ai は緑色になった
    ret %= MOD;
    ret += dfs1(i + 1, r + A[i]);    // Ai は赤色になった
    ret %= MOD;

    return ret;
}

// Ai を見ていて、現在の合計が r のとき、
// R の合計がちょうど s/2 になり、 G の合計もちょうど s/2 になるパターン数
ll dfs2(ll i = 0, ll r = 0) {
    if(i >= N) { return (r == halfS) ? 1 : 0; }

    ll& ret = dp2[i][r];
    if(~ret) { return ret; }

    ret = dfs2(i + 1, r);           // Ai は緑色になった
    ret %= MOD;
    ret += dfs2(i + 1, r + A[i]);    // Ai は赤色になった
    ret %= MOD;

    return ret;

}

signed main()
{
    cin >> N;
    A.resize(N);
    ll sum = 0;
    REP(i, N) {
        cin >> A[i];
        sum += A[i];
    }

    halfS = sum / 2;
    if(sum % 2 != 0) { halfS += 1; }

    // 全パターン
    ll ans = 1;
    REP(i, N) {
        ans *= 3;
        ans %= MOD;
    }

    // どれか一つが s/2 以上の値になってしまうパターン数
    MINUS(dp1);
    ll pat1 = dfs1();
    pat1 *= 3;
    pat1 %= MOD;

    // どれか 2 つが s/2 になるパターン数
    MINUS(dp2);
    ll pat2 = (sum % 2 == 0) ? dfs2() : 0;
    pat2 *= 3;
    pat2 %= MOD;

    ans = (ans + MOD) - pat1;
    ans %= MOD;
    ans += pat2;
    ans %= MOD;

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 465792
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, a, b int
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d", &a)
	fmt.Scanf("%d", &b)

	result := 0
	for i := 1; i <= n; i++ {
		str := strconv.Itoa(i)
		chars := strings.Split(str, "")
		nums := convCharsToNums(chars)
		sum := sum(nums)
		if a <= sum && sum <= b {
			result += i
		}
	}

	fmt.Println(result)
}

func sum(nums []int) int {
	sum := 0
	for _, num := range nums {
		sum += num
	}
	return sum
}

func convCharsToNums(chars []string) []int {
	var res []int
	for _, c := range chars {
		n, _ := strconv.Atoi(c)
		res = append(res, n)
	}
	return res
}


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

const int INF = 1 << 30;

int main(void){

  //initialization
  int N,X;
  int m;
  int min = INF;
  int count;


  cin >> N >> X;
  for(int i; i<N; i++){
    cin >> m;
    X -= m;
    if(min > m) min = m;
  }     

  count = N + X / min;  
  cout << count << "\n";
}


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

int main() {
  int n, m, r;
  cin>>n>>m>>r;
  int rs[r];
  for (int i=0; i<r; i++) {
    cin>>rs[i];
    --rs[i];
  }
  int d[n][n];
  int inf = 1e9;
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      d[i][j] = inf;
    }
    d[i][i] = 0;
  }
  for (int i=0; i<m; i++) {
    int a, b, c;
    cin>>a>>b>>c;
    --a; --b;
    d[a][b] = c;
    d[b][a] = c;
  }

  for (int k=0; k<n; k++) {
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
        if (d[i][k] != inf && d[k][j] != inf &&d[i][j] > d[i][k] + d[k][j]) {
          d[i][j] = d[i][k] + d[k][j];
        }
      }
    }
  }
  long long ans = 1e15;
  sort(rs, rs + r);
  do {
    long long tmp = 0;
    for (int i=0; i<r-1; i++) {
      tmp += d[rs[i]][rs[i+1]];
    }
    ans = min(ans, tmp);
  } while (next_permutation(rs, rs + r));
  cout<<ans<<endl;
}

Measured memory_bytes: 384
n = int(input())
p = list(map(int,input().split()))
# print(p)
cnt = 0
for i in range(n-2):
    p1 = p[i]
    p2 = p[i+1]
    p3 = p[i+2]
    # print(p1,p2,p3)
    if p2>p1 and p2<p3:
        # print(p1,p2,p3)
        cnt+=1
    elif p2<p1 and p2>p3:
        # print(p1,p2,p3)
        cnt+=1
    else:
        pass
print(cnt)


Measured memory_bytes: 38384
import java.util.*;
import java.io.*;

class Main {

	void solve () {

		int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt(), e = in.nextInt();
		int k = in.nextInt();
		
		out.println(e-a<=k ? "Yay!" : ":(");
		
		
	}
	
	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

Measured memory_bytes: 22356
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long int ans=0;
    long long int n;
    cin>>n;
    for (long long int i = 0; i <= n; i++) {
        ans+=i;
    if (i % 3 == 0 && i % 5 == 0)
      ans = ans-i;
    else if (i % 3 == 0)
      ans = ans-i;
    else if (i % 5 == 0)
      ans = ans -i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
#include <iomanip>
#include<numeric>
#include<set>
#include<map>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i,n) for(int i=0;i<n;i++)
char ca;
const int MOD = 1000000007;
ll  c = 0, d = 0, e = 0, f = 0,g=0, n, i, j, k, h, w, o, a[100005], b[10000] = {};
queue<ll> q;
string s;
pair<ll, ll> p[20][20];
vector<vector<ll>> v;
const int MAX = 2005;
long long fac[MAX], finv[MAX], inv[MAX];

int main() {
	cin >> n;
	if (n % 2 == 1) {
		cout << 0;
		return 0;
	}
	j = 10;
	
	while (j <= n) {
		e += (n / j);
		j *= 5;
	}

	cout << e;
	return 0;

}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        h,w,n = LI()
        a = [S() for _ in range(h)]

        def f(i,j):
            if a[i][j] == a[i][j+1]:
                return False
            b = [[c for c in s] for s in a]
            b[i][j],b[i][j+1] = b[i][j+1],b[i][j]
            ff = True
            while ff:
                ff = False
                for i in range(h-2,-1,-1):
                    for j in range(w):
                        if b[i][j] == '.':
                            continue
                        for k in range(i,h-1):
                            if b[k+1][j] == '.':
                                b[k+1][j],b[k][j] = b[k][j],b[k+1][j]
                            else:
                                break

                t = [[None]*w for _ in range(h)]
                for i in range(h):
                    for j in range(w):
                        if b[i][j] == '.':
                            continue
                        tf = True
                        for k in range(1,n):
                            if i+k >= h or b[i+k][j] != b[i][j]:
                                tf = False
                                break
                        if tf:
                            for k in range(n):
                                t[i+k][j] = 1
                        tf = True
                        for k in range(1,n):
                            if j+k >= w or b[i][j+k] != b[i][j]:
                                tf = False
                                break
                        if tf:
                            for k in range(n):
                                t[i][j+k] = 1
                for i in range(h):
                    for j in range(w):
                        if t[i][j] is None:
                            continue
                        b[i][j] = '.'
                        ff = True

            for i in range(h):
                for j in range(w):
                    if b[i][j] != '.':
                        return False
            return True

        r = 'NO'
        for i in range(h):
            for j in range(w-1):
                if f(i,j):
                    r = 'YES'
                    break
        rr.append(r)
        break

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9080
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll h,w,m; cin >> h >> w >> m;
  set<pair<ll,ll>> table;
  vl hcnt(h,0); vl wcnt(w,0);

  rep(i,m){
    ll a,b; cin >> a >> b; a--; b--;
    hcnt[a]++; wcnt[b]++;
    table.insert(make_pair(a,b));
  }
  
  set<ll> avec; set<ll> bvec;
  ll hmax = 0; ll wmax = 0;
  
  rep(i,h){
    hmax = max(hmax,hcnt[i]);
  }
  rep(i,w){
    wmax = max(wmax,wcnt[i]);
  }
  rep(i,h){
    if(hmax == hcnt[i]) avec.insert(i);
  }
  rep(i,w){
    if(wmax == wcnt[i]) bvec.insert(i);
  }
  
  
  ll k = avec.size() * bvec.size();
  
  for(auto p : table){
    ll nowh = p.first; ll noww = p.second;
    if(avec.count(nowh) and bvec.count(noww)) k--;
  }
  
  if(k <= 0) cout << hmax + wmax -1 << endl;
  else cout << hmax + wmax << endl;
  
}

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

int main(){
  int r,D,x0;
  cin>>r>>D>>x0;
  int x1;
  for (int i=0; i<10; i++){
    x1=r*x0-D;
    cout<<x1<<endl;
    x0=x1;
  }
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	char a[4];
	int result = 0;
	std::cin >> a;

	for (int i = 0; i < 4; i++)
	{
		if (a[i] == '+')
		{
			result++;
		}
		else
		{
			result--;
		}
	}
	std::cout << result << std::endl;
	
	return 0;

}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
int n,ans;
struct node
{
	int x,id;
}a[MAXN];
bool cmp(node A,node B)
{
	return A.x<B.x;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].x);
		a[i].id=i;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)
		ans+=((a[i].id&1)!=(i&1));
	printf("%d\n",ans/2);
}

Measured memory_bytes: 896
s = input().rstrip()

leng = len(s)

con = 753

ans = 10000000000


for i in range(leng-2):
    temp = int(s[i:i+3])  # i+3番目の文字は含まれない
    ans = ans if abs(temp-con) > ans else abs(temp-con)

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

  // vector<vector<vector<int> > > DP =  vector<vector<vector<int> > >(100001,vector<vector<int> >(2,vector<int>(2,0)));
void solve(void)
{
  int X;
  cin>>X;
  int Z = X;
  int M = 1;
  int COUNT = 1;
  while(Z > 1)
  {
    Z /=2;
    M +=pow(2,COUNT);
    COUNT++;
    // DEBUG(M);
  }
  cout<<M<<endl;
  return;
  }


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256