akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
    char input[100001];
    char diff[100000];
    int len;
    gets(input);
    for(len = 0; input[len] != '\0'; len++){
        if(len > 0 && input[len-1] != input[len])
            diff[len-1] = 1;
        else
            diff[len-1] = 0;
    }
    int ml = len/2-1;
    int mr = (len+1)/2-1;
    int d;
    for(d = 0; ml-d >= 0 && mr+d < len; d++){
        if(diff[ml-d]){
            printf("%d\n", len-(ml-d+1));
            return 0;
        }
        if(diff[mr+d]){
            printf("%d\n", mr+d+1);
            return 0;
        }
    }
    printf("%d\n", len);
}

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

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

    static class ProblemC_SubarraySum {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int s = in.nextInt();
            int x = s;
            int y = (int) 1e9;
            if (x == y) {
                --y;
            }
            for (int i = 0; i < n; i++) {
                if (i > 0) {
                    out.print(" ");
                }
                out.print(i < k ? x : y);
            }
            out.println();
        }

    }

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

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

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

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

    }
}



Measured memory_bytes: 29716
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        List<int> p = new List<int>();
        for (int i = 0; i < n; i++)
            p.Add(int.Parse(Console.ReadLine()));

        Console.WriteLine(p.Sum() - (p.Max() / 2));
    }
}

Measured memory_bytes: 13268
import scala.io.StdIn.{readLine, readInt}

object Main extends App {
  var str = readLine
  val n = readInt

  for (_ <- 1 to n) {
    val input = readLine.split(" ").map(e => try {
      e.toInt
    } catch {
      case _: Exception => e
    })
    if (input.length == 4) {
      val Array(order: String, pos1: Int, pos2: Int, replaceStr: String) = input
      str = executeOrder(order, pos1, pos2, replaceStr)
    } else {
      val Array(order: String, pos1: Int, pos2: Int) = input
      str = executeOrder(order, pos1, pos2)
    }

    def executeOrder(order: String, pos1: Int, pos2: Int, replaceStr: String = ""): String = {
      val partialString = str.slice(pos1, pos2 + 1)
      order match {
        case s if s == "print" => println(partialString); str
        case s if s == "replace" => str.patch(pos1, replaceStr, pos2 - pos1 + 1).mkString
        case s if s == "reverse" => str.patch(pos1, partialString.reverse, pos2 - pos1 + 1).mkString
      }
    }
  }
}


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/*************************************************************************************/
void file(){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/*************************************************************************************/

const ll maxn=2e5+1,mod=1e9+7;



int main(){

    sync
   // file();
    
    int n;
    cin>>n;
    pair<int,int> ar[n];
    forn(i,n) cin>>ar[i].fi, ar[i].se = i;
    sort(ar,ar+n);
    int ans[n];
    forn(i,n){
    	if(i<n-1){
    		ans[ar[i].se] = ar[n-1].fi;
    	}
    	else{
    		ans[ar[i].se] = ar[n-2].fi;
    	}
    }
    forn(i,n){
    	cout<<ans[i]<<endl;
    }



  return 0;
}

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

const int MAX_N = (int)1e5 + 5;

int n, m, p[MAX_N], grid[MAX_N];

int l, r, d;

int findset(int x) {
	if(p[x] == x) return x;
	int f = p[x];
	p[x] = findset(p[x]);
	grid[x] += grid[f];
	return p[x];
}

int main(void) {
  // Here your code !
	scanf("%d %d", &n ,&m);
	for (int i = 1; i<=n; i++) p[i]=i;
	for (int i = 1; i<=m; i++) {
		int u, v, w;
		scanf("%d %d %d", &l, &r, &d);

		int pl = findset(l), pr = findset(r);

		if(pl != pr) {
			p[pr] = pl;
			grid[pr] = grid[l] + d - grid[r];
		}
		else if(grid[r] - grid[l] != d) {
      printf("No\n");
      return 0;
    }
	}
	printf("Yes\n");
}


Measured memory_bytes: 1024
import sys
import itertools
import bisect

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


n = ni()
flag = 0
for i in range(1, 10):
    for j in range(1, 10):
        if n == i * j:
            flag = 1
if flag:
    print('Yes')
else:
    print('No')




Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

ll dp[4000][4000][5];
int R,C,k;
ll v[4000][4000];

ll run(int i,int j,int now)
{
    if(i>R||j>C)
        return 0;

    if(dp[i][j][now]!=-1)
        return dp[i][j][now];
    ll ans=0;

    //if(j+1<=C)
    {
        ans=max(ans,run(i,j+1,now));
    }
    //if(i+1<=R)
    {
        ans=max(ans,run(i+1,j,0));
    }

    if(v[i][j]!=0&&now<3)
    {
        //if(j+1<=C)
        {
            ans=max(ans,v[i][j]+run(i,j+1,now+1));
            ans=max(ans,run(i,j+1,now));
        }
        //if(i+1<=R)
        {
            ans=max(ans,v[i][j]+run(i+1,j,0));
            ans=max(ans,run(i+1,j,0));
        }

    }
    return dp[i][j][now]=ans;
}

main()
{
    memset(dp,-1,sizeof dp);
    cin>>R>>C>>k;
    for(int i=0; i<k; i++)
    {
        int r,c,x;
        cin>>r>>c>>x;
        v[r][c]=x;
    }
    cout<<run(1,1,0);
}




Measured memory_bytes: 709136
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N = INT()
	A, B = [], []
	for _ in range(N):
		a, b = MAP()
		A.append(a)
		B.append(b)
	
	C = [-1] * N
	for i in range(N-1, -1, -1):
		if A[i]%B[i] == 0:
			C[i] = 0
		else:
			C[i] = B[i]-A[i]%B[i] if B[i]>1 else 0
	# print(C)
	
	ans = 0
	for i in range(N-1, -1, -1):
		c = C[i]
		if B[i] == 1:
			continue
		if c >= ans:
			ans += c-ans
		else:
			if (A[i]+ans)%B[i] == 0:
				continue
			else:
				ans += B[i]-(A[i]+ans)%B[i]
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 14992
#include <iostream>
#include <string>
#include <map>
#define hash __hash

using namespace std;

typedef long long ll;
typedef unsigned long long hash;

const hash BASE = 2340298430918231;
const hash INVBASE = 353531932664012135;

const int MAX_N = 3e5 + 5;

hash _basepow [2 * MAX_N];
hash& basepow (int idx) {
  return _basepow[idx + MAX_N];
}

hash hash_at [MAX_N];
int start_at [MAX_N];

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

  basepow(0) = 1;
  for (int i = 1; i < MAX_N; i++) {
    basepow(i) = basepow(i - 1) * BASE;
  }
  for (int i = -1; i > -MAX_N; i--) {
    basepow(i) = basepow(i + 1) * INVBASE;
  }
  
  int n;
  cin >> n;
  
  string str;
  cin >> str;

  hash cur = 0;
  hash pos = 1;
  int start = 0;
  for (int i = 0; i < (int) str.size(); i++) {
    char c = str[i];
    if (c == '+') cur += pos;
    if (c == '-') cur -= pos;
    if (c == '>') {
      pos *= BASE;
      start++;
    }
    if (c == '<') {
      pos *= INVBASE;
      start--;
    }

    hash_at[i + 1] = cur;
    start_at[i + 1] = start;
  }
  
  map<hash, int> cnt;
  ll ans = 0;
  for (int i = (int) str.size(); i >= 0; i--) {
    hash target = cur * basepow(start_at[i]) + hash_at[i];
    if (cnt.count(target) != 0) {
      ans += cnt[target];
    }

    if (cnt.count(hash_at[i]) == 0) {
      cnt[hash_at[i]] = 0;
    }
    cnt[hash_at[i]]++;
  }

  cout << ans << endl;
}


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

using namespace std;

int main() {
  int n;
  int max_height = 0;
  int result = 0;

  cin >> n;

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

  for (int i = 0; i < n; i++) {
    int height = mountains[i];
    if (height >= max_height) {
      result++;
      max_height = height;
    }
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
A = list(map(int,input().split()))
mx = max(A)
C = Counter(A)
D = {a:True for a in A}
for a in A:
    if C[a]>1: D[a]=False
    for i in range(a*2, mx+1, a):
        D[i]=False
print(sum([D[a] for a in A]))

Measured memory_bytes: 105052
#include<iostream>
using namespace std;
int n,now=7;
int main(){
     cin>>n;
     for(int i=1;i<=1000000;i++){
         now=now*10%(9*n);
         if(now==7){
           	 cout<<i;
             return 0;
         }
     }
  	cout<<-1;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> d(n);
	int sum = 0;
	for( auto &k : d ) cin >> k;
	for( int i = 0; i < n; ++i ){
		for( int j = i+1; j < n; ++j ){
			sum += d[i]*d[j];
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#define n 20000

int main(void)
{
	char str[n];
	scanf("%s", str);		//文字列入力	
		
	int k=0,i,L[n];
	int s1[n],s2[n];
		
	int cnt1=0,cnt2=0;
	int x,y;
	for(i=0; i<strlen(str); i++){		//  \のx座標の位置
		if(str[i]=='\\'){
			s1[cnt1++]=i;
		}
		else if(str[i]=='/' && cnt1>0){
			x=s1[--cnt1];
			y=i-x;
			while(cnt2>0 && s2[cnt2-1]>x){
				y+=L[--cnt2];
			}
			L[cnt2]=y;
			s2[cnt2]=i;
			cnt2++;
		}
	}
	
	for(i=0; i<cnt2; i++){
		k+=L[i];
	}
	printf("%d\n", k);
	printf("%d", cnt2);
	for(i=0; i<cnt2; i++){
		printf(" %d", L[i]);
	}
	printf("\n");
	
	return 0;
}




Measured memory_bytes: 2104
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
  
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
  
        int n = sc.nextInt();
        int q = sc.nextInt();
        Queue<Integer> task = new ArrayDeque<>();
        String[] name = new String[n];
        int[] time = new int[n];
        for(int i = 0; i < n; i++) {
            name[i] = sc.next();
            time[i] = sc.nextInt();
            task.add(i);
        }
 
        sc.close();
 
        int t = 0;
        while(!task.isEmpty()) {
            int i = task.poll();
            if(time[i] <= q) {
                t += time[i];
                System.out.printf("%s %d\n", name[i], t);
            }else {
                t += q;
                time[i] -= q;
                task.add(i);
            }
        }
    }
}


Measured memory_bytes: 104900
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ansP = 0;
    int ansW = 0;
    int ansG = 0;
    int ansY = 0;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        if(s=="P")ansP=1;
        if(s=="W")ansW=1;
        if(s=="G")ansG=1;
        if(s=="Y")ansY=1;
    }
    int ans = ansP+ansW+ansG+ansY;
    if(ans==3)cout << "Three" << endl;
    if(ans==4)cout << "Four" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int N;
    cin >> N;
    int L[N];
    cins(L, L + N);
    Yes((*max_element(L, L + N)) * 2 < accumulate(L, L + N, 0));
}


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

int main(){
    int n;
    cin>>n;
    long long a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=0;
    long long t=0;
    for(int i=0;i<n;i++){
        t+=a[i];
        if(i!=n-1 && t*2>=a[i+1]) ans++;
        else if(i!=n-1 && t*2<a[i+1]) ans=0;
    }
    ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
import sys

class Node:
    def __init__(self):
        self.id = 0
        self.parent = -1
        self.depth = 0
        self.type = "root"
        self.children = []

def addDepth(id, tree):
    tree[id].depth += 1
    for child in tree[id].children:
        addDepth(child, tree)

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    N = int(lines[0])
    del lines[0]

    tree = []
    for i in range(N):
        tree.append(Node())

    for line in lines:
        line = map(int, line.split())
        tree[line[0]].id = line[0]
        tree[line[0]].children = line[2:]

    for node in tree:
        for child in node.children:
            tree[child].parent = node.id
            addDepth(child, tree)
            if tree[child].children:
                tree[child].type = "internal node"
            else:
                tree[child].type = "leaf"

    for node in tree:
        print "node {0.id}: parent = {0.parent}, depth = {0.depth}, {0.type}, {0.children}".format(node)

Measured memory_bytes: 67660
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<ctime>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
    int x = 0; char ch = gc(); bool positive = 1;
    for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
    for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
    return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
    }
    write(a); puts("");
}
ll n,ans;
ll solve(ll a,ll b){return a%b?solve(a*(b-1)/b,b):a/b;}
ll Dec(ll a,ll b){return a-a*(b-1)/b;}
ll Solve(ll a,ll b){
	for(;a%b;){
		ll l=1,r=1e9,ans=0,dec=Dec(a,b);
		for(;l<=r;){
			ll mid=(l+r)>>1;
			if (a-mid*dec>=0&&Dec(a-mid*dec,b)==dec){ans=mid; l=mid+1;}
			else r=mid-1;
		}
		a-=dec*(ans+1);
	}
	return a/b;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++){ll x=read(),y=read();ans^=Solve(x,y);}
	puts(ans?"Takahashi":"Aoki");
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;
typedef long long LL;
int n;
LL a[100050];
int main()
{
    cin>>n;
    for(int i = 0; i < n; i++) cin>>a[i];
    LL sum, ans, ANS = 1e16;
    if(a[0] > 0) sum = a[0], ans = 0;
    else sum = 1, ans = -(a[0]-1);
        for(int i = 1; i < n; i++){
            if(sum > 0){
                if(sum + a[i] >= 0){
                    ans += (sum + a[i]+1);
                    sum = -1;
                } else sum += a[i];
            } else {
                if(sum + a[i] <= 0){
                    ans -= (sum + a[i]-1);
                    sum = 1;
                } else sum += a[i];
            }
        }
        ANS = min(ANS, ans);
        if(a[0] < 0) sum = a[0], ans = 0;
        else sum = -1, ans = (a[0]+1);
        for(int i = 1; i < n; i++){
            if(sum > 0){
                if(sum + a[i] >= 0){
                    ans += (sum + a[i]+1);
                    sum = -1;
                } else sum += a[i];
            } else {
                if(sum + a[i] <= 0){
                    ans -= (sum + a[i]-1);
                    sum = 1;
                } else sum += a[i];
            }
        }
        ANS = min(ANS, ans);
        cout<<ANS<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define _rep(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
#define N 200005
inline bool down(int&x,const int y){return x>y?x=y,1:0;}
int n,a[N];
int main(){
	std::ios::sync_with_stdio(0);
	std::cin.tie(0),std::cout.tie(0);
	std::cin>>n;
	rep(i,1,n) std::cin>>a[i];
	std::sort(a+1,a+n+1);
	int mx=a[n]+1>>1;
	int mi=2e9,id=0;
	rep(i,1,n) if(down(mi,abs(a[i]-mx))) id=i;
	std::cout<<a[n]<<' '<<a[id]<<'\n';
	return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, K;
ll ans;

int main()
{
    cin >> N >> K;
    vector<ll> A(N + 1), s;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i + 1];
        A[i + 1] += A[i];
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j <= N; j++)
        {
            s.push_back(A[j] - A[i]);
        }
    }

    for (int bit = 60; bit >= 0; bit--)
    {
        int cnt = 0;
        ll mask = (1LL << bit);
        ans += mask;
        for (int i = 0; i < s.size(); i++)
        {
            if ((ans & s[i]) >= ans)
                cnt++;
        }

        if (cnt < K)
            ans -= mask;
    }
    cout << ans << endl;
}

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

int main(){
    int N;
    cin>>N;
    vector<int> v(N,0);
    rep(i,N) cin>>v[i];
    sort(v.begin(),v.end());
    double val=v[0]+v[1];
    for(int i=2;i<N;i++) val += v[i]*pow(2,i-1);
    cout<<val/(pow(2,N-1))<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
#define N 100500
long long v[N],su[N],n,s,as,l,r,tp[N],ct;
int main()
{
	scanf("%lld%lld",&n,&s);l=1,r=n;ct=n;
	for(int i=1;i<=n;i++)scanf("%lld%lld",&v[i],&su[i]);
	while(l<r)
	{
		if(s<v[l])su[l]=1e16;if(s>v[r])su[r]=1e16;
		if(su[l]>=su[r])su[l]+=su[r],tp[ct--]=v[r],r--;else su[r]+=su[l],tp[ct--]=v[l],l++;
	}
	tp[1]=v[l];tp[0]=s;
	for(int i=1;i<=n;i++)as+=tp[i]>tp[i-1]?tp[i]-tp[i-1]:tp[i-1]-tp[i];
	printf("%lld\n",as);
}

Measured memory_bytes: 2560
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A;
    ll S = 0;
    rep (i, N) {
        ll a;
        cin >> a;
        S += a;
        A.pb(a);
    }
    vector<ll> X;
    X.pb(S);
    for (ll i = 1; i < N - 1; i += 2) {
        X[0] -= 2 * A[i];
    }
    for (ll i = 1; i < N; ++i) {
        X.pb(2 * A[i - 1] - X[i - 1]);
    }
    rep (i, N) {
        cout << X[i];
        if (i < N - 1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
}


Measured memory_bytes: 3060
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
cnt = 0
pre = -1
for i in range(N):
  idx = A[i]
  cnt += B[idx-1]
  if pre==idx-1:
    cnt += C[pre-1]
  pre = idx
  
print(cnt)

Measured memory_bytes: 3064
object Main extends App {
  @scala.annotation.tailrec
  def loop(chars: Seq[Char], step: Long, acc: Long): Long = chars match {
    case Seq() => acc
    case 'W' :: xs =>
      loop(xs, step, acc + step)
    case _ =>
      val (bs, xs) = chars.span(_ != 'W')
      loop(xs, bs.length + step, acc)
  }

  val sc = new java.util.Scanner(System.in)
  println(loop(sc.next().toCharArray.toList, 0, 0))
}


Measured memory_bytes: 66288
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

ll Cost(ll from, ll to){
    if (from > to){
        return from - to;
    } else if (from <= to){
        if ((to - from) % 2 == 0){
            return (to-from) / 2;
        } else {
            return ((to+1) - from) / 2 + 1;
        }
    }
}


int main() {
    vector<ll> v{};
    for (auto &&i: boost::irange(0LL, 3LL)) {
        ll l;
        cin >> l;
        v.emplace_back(l);
    }
    ll min_cost{numeric_limits<ll>::max()};
    for (auto &&i: boost::irange(-100LL, 100LL)){
        ll cost = Cost(v.at(0), i) + Cost(v.at(1), i) + Cost(v.at(2), i);
        min_cost = min(min_cost, cost);
    }
    cout << min_cost;
    return 0;
}

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

int main(){
    int n, x[100], y[100], fmax;
    double f;
    double D1 = 0;
    double D2 = 0;
    double D3 = 0;
    double D0 = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    for(int i = 0; i < n; i++){
        cin >> y[i];
    }
    for(int i = 0; i < n; i++){
        f = fabs(x[i] - y[i]);
        D1 += f;
        D2 += f*f;
        D3 += pow(f, 3);
        if(i == 0){
            fmax = f;
        } else if(fmax < f) {
            fmax = f;
        }
    }
    D2 = sqrt(D2);
    D3 = pow(D3, 1.0/3.0);
    D0 = fmax;
    
    printf("%f\n%f\n%f\n%f\n", D1,D2, D3, D0);
    return 0;
}




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

ans = [0]*10050

for i in range(1,105):
  for j in range(1,105):
    for k in range(1,105):
      v = (i+j+k)**2-(i*j+i*k+j*k)
      if v < len(ans):
        ans[v] += 1
  
for x in range(1,N+1):
  print(ans[x])

Measured memory_bytes: 9236
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	cin >> N;
	map<string, int> name;
	int mx = 0;
	for (int i = 0; i < N; i++)
	{
		string S;
		cin >> S;
		if (name.count(S))
			name[S]++;
		else
			name[S] = 1;
		mx = max(mx, name[S]);
	}
	//cout << "------------" << endl;
	for (auto p : name)
	{
		if (p.second == mx)
			cout << p.first << endl;
	}
}



Measured memory_bytes: 25216
from collections import deque
n,m=map(int,input().split())
root=[[] for _ in range(n)]
for i in range(m):
	a,b=map(int,input().split())
	root[a-1].append(b-1)
	root[b-1].append(a-1)
times=[0]*n
sign=[-1]*n
sign[0]=0
color=[False]*n
que=deque([0])
while que: #qが空でないのはこう表現できる
	i=que.popleft()
	if color[i]==False:
		for edge in root[i]:
			if color[edge]==False and sign[edge]==-1: #相方が親じゃなければ(親ならすでに探索済みのはず)
				sign[edge]=i
				que.append(edge)
		color[i]=True
print('Yes')
for i in range(n-1):
	print(sign[i+1]+1)

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

const int mod=998244353;
int n,nw,f[1000010],mu[1000010],ans,F[1000010];
vector<int> v[1000010];
bool bo[1000010];

void add(int &x,int y) {x=(x+y>=mod?x+y-mod:x+y);}

int main()
{
	for (int i=1; i<=1000000; i++) mu[i]=1;
	for (int i=2; i<=1000000; i++) if (!bo[i])
		for (int j=i; j<=1000000; j+=i) 
		{
			bo[j]=1;
			if (j%(1ll*i*i)==0) mu[j]=0; else mu[j]*=-1;
		}
	for (int i=1; i<=1000000; i++)
	{
		f[i]=1ll*mu[i]*i%mod;
		for (int j=0,sz=v[i].size(); j<sz; j++) f[i]=(f[i]+1ll*mu[v[i][j]]*v[i][j])%mod;
		if (f[i]<0) f[i]+=mod;
		for (int j=1; i*j<=1000000; j++) v[i*j].push_back(i);
	}
	scanf("%d",&n),ans=0;
	for (int i=1; i<=n; i++)
	{
		scanf("%d",&nw);
		for (int j=0,sz=v[nw].size(); j<sz; j++)
			ans=(ans+1ll*F[v[nw][j]]*f[v[nw][j]]%mod*(nw/v[nw][j]))%mod,add(F[v[nw][j]],nw);
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree < int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update >
#define smallk order_of_key
#define kth find_by_order
*/

#define nl '\n'
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb push_back

typedef long long ll;

const int N = (int)1e5 + 123;
const int M = 1e9 + 7;
const int K = 500;

int n;
vector<int> g[N];
long long dp[N][3];

int solve(int v, int t, int p){
    if(dp[v][t] != -1){
        return dp[v][t];
    }
    dp[v][t] = 1;
    for(int to : g[v]){
        if(to == p) continue;
        int cnt = 1;
        if(t == 1) cnt = solve(to, 2, v) % M;
        else cnt = (solve(to, 2, v)  + solve(to, 1, v)) % M;
        dp[v][t] *= cnt;
        dp[v][t] %= M;
    }
    return dp[v][t] % M;
}
int main(){

    ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

    #ifdef LOCAL
        freopen("B.txt", "r", stdin);
    #endif // LOCAL

    cin >> n;
    for(int i = 1; i <= n; ++i){
        dp[i][1] = dp[i][2] = -1;
    }
    for(int i = 1, x, y; i < n; ++i){
        cin >> x >> y;
        g[x].pb(y);
        g[y].pb(x);
    }

    cout << (solve(1, 1, -1) + solve(1, 2, -1)) % M;
    return 0;
}



Measured memory_bytes: 16384
//
//AtCoder Beginner Contest 167
//C - Skill Up
//

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

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()

using ll = long long;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
    int n, m, x;

    cin >> n >> m >> x;

    int c[n];
    int a[n][m];

    REP(i, n){
        cin >> c[i];
        REP(j, m) cin >> a[i][j];
    }

    int ans = INT32_MAX;

    vector<bool> bitOK;
    REP(bit, (1 << n)){
        vector<int> s;
        REP(i, n){
            if (bit & (1 << i)) { // 列挙に i が含まれるか
                s.push_back(i);
            }
        }

        bool flag = false;
        int cSum = 0;
        int aSum[m];
        REP(i, m) aSum[i] = 0;

        //cout << bit << ": {";
        REP(i, s.size()) {
            //cout << s[i] << " ";
            cSum += c[s[i]];
            REP(j, m){
                aSum[j] += a[s[i]][j];
            }
            bool ck = true;
            REP(j, m){
                if (aSum[j] < x) {
                    ck = false;
                    break;
                }
            }
            if (ck) {
                flag = true;
                break;
            }
        }
        //cout << "}" << flag << ":" << cSum << endl;

        bitOK.push_back(flag);

        if (flag){
            ans = min(ans, cSum);
        }
    }

    if (ans == INT32_MAX) ans = -1;
   
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3616
#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(){
    string s,t;
    cin >> s >> t;
    int l = s.length();
    int m = t.length();
    if(l+1==m && s == t.substr(0,l)){
        cout << "Yes" << "\n";
        return 0;
    }
    cout << "No" << "\n";
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main(){
    double n;
    double k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    double one_pos ;
    for(int i=0;i<n;i++){
        if(a.at(i)==1) one_pos = i; 
    }
    cout << ceil((n-1)/(k-1)) << "\n";
    return 0;
}

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

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

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int gcd(ll a, ll b){
    if(a<b){
        int tmp = a;
        a = b;
        b = tmp;
    }

    ll r = a%b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

int main(){
    int n;
    cin >> n;
    int a[n];
    int ans = 0;
    REP(i, n) {
        cin >> a[i];
        ans += a[i] - 1;
    }
    cout << ans << endl;

    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define lli long long int
#define pb push_back
#define pob pop_back
#define rep(i,a,b) for(lli i=a;i<b;i++)
#define repv(a,b) for(int i=a;i>=b;i--)
#define itr vector<lli> :: iterator
#define maximum(a,b,c)  max(a,max(b,c))
#define minimum(a,b,c) min(a,min(b,c))
#define tim clock_t

inline void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
map<lli,lli> mp1,mp2;
void call(lli n,lli flag)
{
	if(flag==0)
	{
	for(lli i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(n/i==i)mp1[i]++;
			else
			{
				mp1[i]++;
				mp1[n/i]++;
			}
		}
	}
	return ;
	}
	else
	{
	for(lli i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(n/i==i)mp2[i]++;
			else
			{
				mp2[i]++;
				mp2[n/i]++;
			}
		}
	}
	return ;
	}
}
int main()
{
	fast();
	lli a,b,k;
	cin>>a>>b>>k;
	call(a,0);
	call(b,1);
		vector<lli> v;	
	for(lli i=0;i<1001;i++)
	{
		if(mp1[i]!=0 && mp2[i]!=0)
		{
			v.push_back(i);
		}
	}
	sort(v.begin(),v.end(),greater<lli>());
	cout<<v[k-1];
	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * for (int i = 0; i < N; i++) {}
 * System.out.println();
 * HashMap<Integer, Integer> hm = new HashMap<>();
 * int[] s = new int[M];
 * ArrayDeque<Integer> deq = new ArrayDeque<>();
 *
 */
public class Main implements Runnable { //クラス名はMain1

	public static void main(String[] args) {
		Thread.setDefaultUncaughtExceptionHandler((t, e) -> System.exit(1));
		new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行
	}

	public void run() {
		FastScannerMain1 sc = new FastScannerMain1(System.in);

		try {
			//String S = sc.nextLine().trim();
			int K = sc.nextInt();
			int[] a = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4,
					1, 4, 1, 51 };
			//long l = sc.nextLong();
			//ArrayList<Integer> arr = new ArrayList<Integer>();

			for (int i = 1; i <= a.length; i++) {
				if (i == K) {
					System.out.println(a[i - 1]);
				}
			}

			System.out.println();

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}

//高速なScanner
class FastScannerMain1 {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScannerMain1(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

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

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}

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

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 28500
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scan=new Scanner(System.in);
		char ch=(char)System.in.read();
		switch(ch) {
		case 'A':System.out.println("T");break;
		case 'G':System.out.println("C");break;
		case 'C':System.out.println("G");break;
		case 'T':System.out.println("A");break;
		}
	}
}

Measured memory_bytes: 21588
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define setpr(xval) cout<<fixed<<setprecision(12)<<xval<<endl;
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,m,k,ans;
void solve()
{
    cin>>n>>ans;
    for(ll i=1;i<n;i++)
    {
        ll a;
        cin>>a;
        ans=__gcd(ans,a);
    }
    cout<<ans<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,m=1;
    cin>>n;
    for(i=1;i<=9;i++)
    {
        if(!(n%i)&&(n/i>=1&&n/i<=9))
        {
            puts("Yes");
            m=0;
            break;

        }
    }
    if(m)
        puts("No");
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

void _main() {
  int H, W;
  cin >> H >> W;
  char s[H][W];
  rep(i, 0, H) cin >> s[i];

  int dx[4] = { 0, 1, 0, -1};
  int dy[4] = {-1, 0, 1,  0};
  rep(i, 0, H) rep(j, 0, W) {
    if ('.' == s[i][j]) continue;
    bool can = false;
    rep(k, 0, 4) {
      int ny = i + dy[k];
      int nx = j + dx[k];
      if (0<=nx && W>nx && 0<=ny && H>ny) {
        if ('#' == s[ny][nx]) can = true;
      }
    }
    if (!can) {
      cout << "No" << "\n";
      return;
    }
  }
  cout << "Yes" << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  string S;
  cin >> S;
  ll N = S.size();
  ll power[N];
  power[0] = 1;
  for (ll i = 1; i < N; i++) {
    power[i] = power[i-1] * 10;
    power[i] %= 13;
  }
  ll dp[N][13];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 13; j++) {
      dp[i][j] = 0;
    }
  }
  if (S[N-1] == '?') {
    for (int i = 0; i < 10; i++) {
      dp[0][i] = 1;
    }
  } else {
    int a = S[N-1] - '0';
    dp[0][a] = 1;
  }

  for (int i = 1; i < N; i++) {
    if (S[N-i-1] != '?') {
      int a = S[N-i-1] - '0';
      int num = (power[i] * a) % 13;
      for (int j = 0; j < 13; j++) {
        dp[i][(j+num)%13] = dp[i-1][j];
      }
    } else {
      for (int j = 0; j < 13; j++) {
        for (int k = 0; k < 10; k++) {
          dp[i][((k*power[i]) + j)%13] += dp[i-1][j];
          dp[i][((k*power[i]) + j)%13] %= Mod;
        }
      }
    }
  }
  cout << dp[N-1][5] << endl;
  return 0;
}

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

int main(){
	int tmp;
	stack<int>st;
	while(cin>>tmp){
		if(tmp>0){
			st.push(tmp);
		}
		else if(tmp==0){
		cout<<st.top()<<endl;
		st.pop();
		}
	}
}

Measured memory_bytes: 1200
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var char_count = new int[26];
            while(true)
            {
                //??????????????????
                var read = Console.ReadLine();
                //var temp_string = read.Split(' ');

                if (read == null || read.Length == 0)
                {
                   break;
                }

                //???????????£????????????char?????????????§£
                var read_arry = read.ToCharArray();


                //char?????????1?????????????????????
                foreach(char c in read_arry)
                {
                    int UTF16_code=(int)char.ToLower(c);
                    if(UTF16_code>=97&&UTF16_code<=123)
                    {
                        char_count[UTF16_code - 97]++;
                    }

                }

            }

            int roop_count = 0;
            foreach (int temp in char_count)
            {
                Console.WriteLine(Convert.ToChar(roop_count + 97) + " : " + temp);
                roop_count++;
            }
            
        }
    }
}

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[100];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	ll ret=1;
	ll ng=1;
	cin>>N;
	FOR(i,N) {
		cin>>x;
		ret*=3;
		if(x%2==0) ng*=2;
	}
	cout<<ret-ng<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<HashMap<Integer, Integer>> issues = new ArrayList<HashMap<Integer, Integer>>();
    for (int i=0; i<n; i++) {
      HashMap<Integer, Integer> tmpMap = new HashMap<Integer, Integer>();
      int issueCnt = sc.nextInt();
      for (int j=0; j<issueCnt; j++) {
        tmpMap.put(sc.nextInt(), sc.nextInt());
      }
      issues.add(tmpMap);
    }
    
    int result = 0;
    int max = 0;
    int breakFlg = 0;
    for (int i=0; i<Math.pow(2, n); i++) {
      result = 0;
      for (int j=0 ; j<n; j++) {
        if ((1&(i>>j))==1) {
          HashMap<Integer, Integer> curIssues = issues.get(j);
          result++;
          if (curIssues.size()>0) {
            for(Integer k : curIssues.keySet()) {
              int tmp = i;
              if (curIssues.get(k)==1) {
                if (((tmp>>(k-1))&1)==1) {
                  
                }
                else {
                  breakFlg = 1;
                  break;
                }
              }
              else {
                if (((tmp>>(k-1))&1)==0) {
                  
                }
                else {
                  breakFlg = 1;
                  break;
                }
              }
            }
          }
        }
      }
      
      if (breakFlg==1) {
        breakFlg = 0;
        continue;
      }
      if (max<result) {
        max = result;
      }
    }
    
    System.out.println(max);
  }
}


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

int H, W;
vector< vector< char > > field;

int rec(int x, int y, char ch){
	if(field[x][y] == '.' || field[x][y] != ch)
		return 0;
	field[x][y] = '.';
	
	if(x > 0)
		rec(x-1, y, ch);
	if(x < H - 1)
		rec(x+1, y, ch);
	if(y > 0)
		rec(x, y-1, ch);
	if(y < W - 1)
		rec(x, y+1, ch);
	return 1;
}

int main(){
	string temp;
	int count;
	
	while(cin >> H >> W, H){
		count = 0;
		field.resize(H);
		for(int i = 0; i < H; ++i){
			field[i].resize(W);
			cin >> temp;
			for(int j = 0; j < temp.length(); ++j)
				field[i][j] = temp[j];
		}
		
		for(int i = 0; i < H; ++i)
			for(int j = 0; j < W; ++j)
				count += rec(i,j,field[i][j]);
		
		cout << count << endl;
	}
}

Measured memory_bytes: 1704
import java.util.Scanner;

public class Main {
  static String s;

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

    s = sc.next();
    int n = s.length();

    long ans = Long.parseLong(s);
    for(int d = 1; d <= n - 1; d++){
      for(int i = 0; i + d <= n; i++){
        long tmp = Long.parseLong(s.substring(i, i + d));
        if(i != 0 && i + d != n){
          ans += tmp * (1 << (n - d - 2));
        }
        else{
          ans += tmp * (1 << (n - d - 1));
        }
      }
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 9556
#include <iostream>
#include <cstdio>
using namespace std;
string n;
signed main()
{
        cin>>n;
        int len=n.size(),sum=0;
        for (int i=0; i<len; i++) sum=sum+(n[i]^48);
        if (sum%9) puts("No");
        else puts("Yes");
        return 0;
}


Measured memory_bytes: 3780