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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll K = 62;

bool bit(ll x, ll k) {
	return x & (1LL << k);
}

bool has_subset(vl a, ll s) {
	ll n = sz(a);
	
	ll r = 0;
	FOR(k,0,K) {
		if (r == n) break;
		FOR(i,r,n) {
			if (bit(a[i],k)) {
				swap(a[i],a[r]);
				break;
			}
		}
		if (!bit(a[r],k)) continue;
		
		FOR(i,r+1,n) if (bit(a[i],k)) a[i] ^= a[r];

		if (bit(s,k)) s ^= a[r];
		r++;
	}
	return s == 0;	
}

bool has_subset_naive(vl a, ll s) {
	ll n = sz(a);
	FOR(mask,0,1 << n) {
		ll x = 0;
		FOR(i,0,n) if (mask & (1 << i)) x ^= a[i];
		if (x == s) return true;
	}
	return false;
}

void stress() {
	FOR(i,0,1000) {
		ll n = 1 + rand() % 5;
		vl a(n);
		FOR(i,0,n) a[i] = rand() % 16;
		ll s = rand() % 16;
	
		if (has_subset(a,s) != has_subset_naive(a,s)) {
			cout << has_subset(a,s) << endl;
			for (ll x: a) cout << x << " ";
			cout << s << endl;
			return;
		}
	}
}

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

	// stress();

	ll n; cin >> n;
	vl a(n);
	FOR(i,0,n) cin >> a[i];

	ll s = 0;
	FOR(i,0,n) s ^= a[i];
	
	ll x = 0;
	FORD(k,0,62) {
		if (s & (1LL << k)) {
			FOR(i,0,n) a[i] &= ~(1LL << k);
		} else {
			vl b(n);
			FOR(i,0,n) b[i] = a[i] >> k;
			if (has_subset(b, (x >> k) | 1)) x |= 1LL << k;
			// cerr << k << " " << x << endl;
		}
	}

	ll res = x + (s^x);
	cout << res << endl;
}



Measured memory_bytes: 2672
from collections import deque
import bisect
N=int(input())
D=deque()
L=["3","5","7"]
#ans3
i1=0
i2=0
i3=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            s=L[i1]+L[i2]+L[i3]
            if "3" in s and "5" in s and "7" in s:
                D.append(int(s))
i1=0
i2=0
i3=0
i4=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                s=L[i1]+L[i2]+L[i3]+L[i4]
                if "3" in s and "5" in s and "7" in s:
                    D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]
                    if "3" in s and "5" in s and "7" in s:
                        D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]
                        if "3" in s and "5" in s and "7" in s:
                            D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
i7=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        for i7 in range(3):
                            s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]+L[i7]
                            if "3" in s and "5" in s and "7" in s:
                                D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
i7=0
i8=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        for i7 in range(3):
                            for i8 in range(3):
                                s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]+L[i7]+L[i8]
                                if "3" in s and "5" in s and "7" in s:
                                    D.append(int(s))
i1=0
i2=0
i3=0
i4=0
i5=0
i6=0
i7=0
i8=0
i9=0
for i1 in range(3):
    for i2 in range(3):
        for i3 in range(3):
            for i4 in range(3):
                for i5 in range(3):
                    for i6 in range(3):
                        for i7 in range(3):
                            for i8 in range(3):
                                for i9 in range(3):
                                    s=L[i1]+L[i2]+L[i3]+L[i4]+L[i5]+L[i6]+L[i7]+L[i8]+L[i9]
                                    if "3" in s and "5" in s and "7" in s:
                                        D.append(int(s))
d=list(D)
d.sort()
print(bisect.bisect_right(d,N))

Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0;i < (int)(n);i++)
int main() {
  int n, a;
  cin >> n;
  set<int> v;
  rep(i, n) {
    cin >> a;
    if(v.count(a)) v.erase(a);
    else v.insert(a);
  }
  cout << v.size() << endl;
}

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

long long N, K, ans = 0;

int main(){
  cin >> N >> K;
  if(K==0){
	cout << N*N << endl;
	return 0;
  }
  for(int i = 1; i<=N; i++)
	if(i-1 >= K){
	  ans += N/i*(i-K);
	  if(N%i-K+1>=1) ans += N%i-K+1;
	}
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	int a, b;
  	cin >> a >> b;
  	if (a >= 13){
      cout << b << endl;
    }
  	
  	else if ( 5 >= a ){
      cout << 0 << endl;
 
    }
  
  	else {
      cout << b/2 << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
#define N (100010)
int n, a[N];
int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i){
        scanf("%d", a+i);
    }
    int tot = abs(a[1]);
    for (int i = 1; i <= n; ++i){
        tot += abs(a[i]-a[i+1]);
    }
    for (int i = 1; i <= n; ++i){
        printf("%d\n", tot - abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]));
    }
}

Measured memory_bytes: 1536
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
vector<ll> tree[1010];
ll dp[1010] = {};
ll X[1010];
void dfs(ll cur, ll par){
    vector<ll> nxt(X[cur]+1, INF);
    nxt[0] = 0;
    for(auto &e: tree[cur]){
        if(e == par) continue;
        dfs(e, cur);
        // vector<ll> prv = move(nxt);
        vector<ll> prv(X[cur]+1);
        rep(i,0,X[cur]+1) prv[i] = nxt[i];
        rep(i,0,X[cur]+1) nxt[i] = INF;
        rep(v,0,X[cur]+1){
            if(v + dp[e] <= X[cur] && prv[v] < INF){
               nxt[v + dp[e]] = min(nxt[v + dp[e]], prv[v] + X[e]); 
            }
            if(v + X[e] <= X[cur] && prv[v] < INF){
                nxt[v + X[e]] = min(nxt[v + X[e]], prv[v] + dp[e]);
            }
        }
    }
    ll res = INF;
    rep(i,0,X[cur]+1) res = min(res, nxt[i]);
    dp[cur] = res;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll P[1010];
    rep(i,0,N-1){
        cin >> P[i];
        P[i]--;
        tree[P[i]].push_back(i+1);
    }
    rep(i,0,N) cin >> X[i];
    rep(i,0,N) dp[i] = INF;
    dfs(0, -1);
    if(dp[0] != INF){
        print("POSSIBLE");
    }else{
        print("IMPOSSIBLE");
    }

}

Measured memory_bytes: 11152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int a,b,c;
    cin>>a>>b;
    c = a+b;
    if(c<10)cout<<c<<endl;
    else cout<<"error"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,i,x,sum;
bitset<4000020>f;
int main(){
	scanf("%d",&n);
	f[0]=1;
	for(i=1;i<=n;i++){
		scanf("%d",&x);
		f|=f<<x;
		sum+=x;
	}
	for(i=(sum+1)/2;i<=sum;i++)if(f[i]){
		printf("%d",i);return 0;
	}
}

Measured memory_bytes: 1664
//Meri hr baat bs yaad hai tumhari , mera apna koi kissa nhi!!
#include<iostream>
#include<bits/stdc++.h>
#define ll long long int 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define md 1000000007
#define fat 998244353 
double PI=3.1415926535;
const int N =  (int)(1 * 1e6 + 10);
using namespace std;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
ll n , m ;
char a[1005][1005];


int main()

{
    cin>>n>>m;
    for(ll i = 0 ; i < n ; i++)
    {
        for(ll j = 0 ; j < m ; j++)
        {
            cin>>a[i][j];
            //if(a[i][j]=='#')dp[i][j]=0;
        }
    }
    ll dp[n][m];
    dp[0][0]=1;


    for(ll i = 0 ; i < n ; i++)
    {
        for(ll j = 0 ;j <m ; j++)
        {
            if(a[i][j]=='#')
            {
                dp[i][j]=0;
                continue;
            }

            if(i==0 && j==0)
            {
                dp[i][j]=1;
                continue;
            }
            if(i==0)
            {
                dp[i][j]=dp[i][j-1];
                continue;
            }
            if(j==0)
            {
                dp[i][j]=dp[i-1][j];
                continue;
            }

            dp[i][j]=(dp[i-1][j]%md+dp[i][j-1]%md)%md;
        }
    }
    cout<<dp[n-1][m-1]<<endl;

}

Measured memory_bytes: 9088
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500*i+100*j+50*k) == X:
                cnt = cnt + 1
print(cnt)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    while (true) {
      int x = stdin.nextInt();
      int y = stdin.nextInt();
      if (x == 0 && y == 0) {
        break;
      } else if (x > y) {
        System.out.printf("%d %d%n", y, x);
      } else {
        System.out.printf("%d %d%n", x, y);
      }
    }
  }

}

Measured memory_bytes: 34216
s = input()

# パターン AABB ABAB ABBA
if s[0]==s[1] :
    if s[2]==s[3] and s[0]!=s[2]:
        print('Yes')
    else :
        print('No')
elif s[0]==s[2] and s[0]!=s[1]:
    if s[1]==s[3]:
        print('Yes')
    else :
        print('No')
elif s[2]==s[1] and s[0]!=s[2]:
    if s[0]==s[3]:
        print('Yes')
    else :
        print('No')
else :
    print('No')

Measured memory_bytes: 3064
import sys, fractions
input = sys.stdin.readline
n,x = map(int,input().split())
a = tuple(map(int,input().split()))
b = [0] * n
c = abs(a[0] - x)
for i in range(1,n):
  c = fractions.gcd(c,abs(a[i]-x))
print(c)

Measured memory_bytes: 16368
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
using namespace std;
//start
const int limit = 2e5 + 1;
int k;
vector<int> g[limit];
bool vis[limit];

void dfs(int s,int k){
    if(k >= 2) return;

    for(auto it:g[s]){
        if(!vis[it]){
            vis[it] = true;
            dfs(it, k+1);
        } 
    }
}


int main(){
    ll l,r;
    cin >> l >>r;

    ll ans = INF;
    
    for(ll i = l; i<=r ; i++){
        for(ll j = i+1 ; j <= r;j++){
            if((i*j)%2019 < ans) ans = (i*j)%2019;

            if((i*j)%2019 == 0){
                cout << 0 <<endl;
                return 0;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4992
t = []

for i in range(8):
    t.append(input())
    
print(90)
for i in range(8):
    for j in range(8):
        print(t[7-j][i],end="")
    print("")

print(180)
for i in range(8):
    for j in range(8):
        print(t[7-i][7-j],end="")
    print("")

print(270)
for i in range(8):
    for j in range(8):
        print(t[j][7-i],end="")
    print("")


Measured memory_bytes: 5584
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.util.InputMismatchException;
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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            for (int i = 111; i < 1000; i += 111) {
                if (n <= i) {
                    out.println(i);
                    return;
                }
            }

            throw new IllegalArgumentException();
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 23124
#include<stdio.h>
 
int main(void)
 
{
 
 int n,x,min,max;
 
 long sum;
 
 
 int i;
 
 
 scanf("%d %d",&n,&x);
 
 min=max=sum=x;
 
 
 for(i=1; i<n; i++){
 
  scanf("%d",&x);
 
  sum +=x;
 
 
  if(max<x)
 
 
   max=x;
 
 
  if(min>x)
 
 
   min=x;
 
 
  }
 
 
  printf("%d %d %ld\n",min,max,sum);
 
 
 return 0;
 
 
}

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

int main() {
    string S;
    ll K;
    cin >> S >> K;
    ll N = S.size();
    ll flag; // 1が先頭から数えてflag個ある
    for (int i = 0; i < N; i++) {
        if (S[i] != '1') {
            flag = i;
            break;
        }
    }
    if (flag >= K) cout << '1' << endl;
    else cout << S[flag] << endl;
    return 0;
}

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

using namespace std;

#define endl '\n'

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  
  string s;
  cin >> s;

  if(s == "ABC")
    cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
  

  return 0;
}

Measured memory_bytes: 3560
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as M
import           Data.List
import           Data.Maybe
import           Data.Ord
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readLine :: Read a => IO [a]
readLine = map (read . BS.unpack) . BS.words <$> BS.getLine

readLines :: Read a => Int -> IO [[a]]
readLines n = replicateM n readLine

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main :: IO ()
main = do
  [n] <- readLine
  a   <- readLine
  putStrLn $ solve n a

solve :: Int -> [Int] -> String
solve n a | length a == a' = "YES"
          | otherwise      = "NO"
  where a' = length $ group $ sort a



Measured memory_bytes: 45820
'''
ある平面のブロック数×(0,1)
一つでも偶数があれば、均等分割可能
すべて奇数のとき、
ある平面のブロック数を最小となるようにすると、その数が答えになる
'''

arr = list(map(int, input().split()))

ret = -1
if 0 in list(map(lambda x: x % 2, arr)):
    ret = 0
else:
    arr_sorted = sorted(arr)
    ret = arr_sorted[0] * arr_sorted[1]
print(ret)

Measured memory_bytes: 3060
#include <stdio.h>
int H;
int a[1000000];
void maxheapfy(int i){
    int left = 2*i;
    int right = 2*i +1;
    int largest;
    if(a[i]<a[right] && right<=H) largest = right;
    else largest = i;
    if(a[left]>a[largest] && left<=H ) largest = left;
    
    if(largest != i){
        int tmp = a[largest];
        a[largest] = a[i];
        a[i] = tmp;
        maxheapfy(largest);
    }
    
    
}

void build_maxheap(int i){
    
    for(i=H/2;i>=1;i--){
        maxheapfy(i);
    }
}

int main(){
    int i;
    scanf("%d",&H);
    for(i=1;i<=H;i++)scanf("%d",&a[i]);
    build_maxheap(i);
    for(i=1;i<=H;i++)printf(" %d",a[i]);
    printf("\n");
    return 0;
}



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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
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; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353
const ll INF = 1e10;


vector<int> sieve(int n) {
    vector<int> primes(n);
    for (int i = 2; i < n; ++i) {
        primes[i] = i;
    }
    for (int i = 2; i * i < n; ++i) {
        if (primes[i]) {
            for (int j = i * i; j < n; j += i) {
                primes[j] = 0;
            }
        }
    }
    return primes;
}


int main() {
    int N; cin >> N;
    vi primes = sieve(55556);

    int res = 0;

    for(int p : primes){
        if(p % 5 == 3){
            res++;
            cout << p << endl;
        }
        if(res == N) break;
    }
    
}


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

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

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

#define MOD 1000000007
#define INF 2000000000
int w, h;
int m[22][22];
int cost[11][11];
vector<pair<int, int> > v;
int sr, sc;

int costculc(int r1, int c1, int r2, int c2)
{
	int cmemo[22][22];
	rep(i, 22) rep(j, 22) cmemo[i][j] = INF;
	cmemo[r1][c1] = 0;
	queue<pair<int, int> > q;
	q.push(MP(r1, c1));
	while (!q.empty()) {
		int r, c;
		r = q.front().first;
		c = q.front().second;
		int dr[] = {-1, 0, 1,  0};
		int dc[] = { 0, 1, 0, -1};
		rep(i, 4) {
			int nr = r + dr[i];
			int nc = c + dc[i];
			if (cmemo[nr][nc] != INF || m[nr][nc] == -1) continue;
			cmemo[nr][nc] = cmemo[r][c] + 1;
			q.push(MP(nr, nc));
		}
		q.pop();
	}
	return cmemo[r2][c2];
}

signed main()
{
	cin >> w >> h;
	while (w) {
		v.clear();
		rep(i, 22) rep(j, 22) m[i][j] = -1;
		rep(i, 11) rep(j, 11) cost[i][j] = INF;
		rep(i, 11) cost[i][i] = 0;
		reps(i, 1, h+1) reps(j, 1, w+1) {
			CIN(char, c);
			if (c == '.') m[i][j] = 0;
			if (c == 'o') {
				m[i][j] = 1;
				v.insert(v.begin(), MP(i, j));
				sr = i;
				sc = j;
			}
			if (c == '*') {
				m[i][j] = 2;
				v.PB(MP(i, j));
			}
			if (c == 'x') m[i][j] = -1;
		}
		rep(i, v.size()) reps(j, i+1, v.size()) {
			cost[i][j] = cost[j][i] = costculc(v[i].first, v[i].second, v[j].first, v[j].second);
		}
		vector<int> t;
		int mi = INF;
		rep(i, v.size()-1) t.PB(i+1);
		do {
			int be = 0;
			int res = 0;
			rep(i, t.size()) {
				res += cost[be][t[i]];
				be = t[i];
			}
			mi = min(mi, res);
		} while (PERM(t));
		if (mi == INF) cout << -1 << endl;
		else cout << mi << endl;
		cin >> w >> h;
	}
}


Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
            String input = scanner.nextLine();
            String[] inputs = input.split(" ");

            int x = Integer.parseInt(inputs[0]);
            int a = Integer.parseInt(inputs[1]);

            if (x < a) {
                System.out.println(0);
            } else {
                System.out.println(10);
            }


            
            scanner.close();
    }
}

Measured memory_bytes: 21588
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    # ループしているところを見つける
    path = [1]
    dic = [0] * n
    dic[0] = 1
    current = 0
    looping = False
    loop_st = -1
    loop_ed = -1
    for i in range(n):
        _next = a[current]
        if dic[_next-1] == 1:
            loop_st = path.index(_next)
            loop_ed = len(path)
            looping = True
            break
        dic[_next-1] = 1
        # if _next in path:
        #     loop_st = path.index(_next)
        #     loop_ed = len(path)
        #     looping = True
        #     break
        path.append(_next)
        current = _next-1

    if looping:
        if loop_ed - 1 >= k:
            print(path[k])
        else:
            len_loop = loop_ed - loop_st
            z = (k - loop_st) % len_loop
            print(path[loop_st + z])
    else:
        print(path[k])


main()


Measured memory_bytes: 31988
#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 ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)

ll maxn=365;
ll d=0;
ve <ll> c(26);
ve <ve <ll>> v(maxn,ve <ll> (26));
ve <ll> last(26,-1);
ve <ll> assigned(maxn,-2);
ll ini=0;
//ll a[26][365][2];

ll score(){
	ll sats=0;
	FOR(i,0,d){
	FOR(j,0,26){
		sats-=c[j]*(i-last[j]);
	 }
	ll take=assigned[i];
	sats+=v[i][take]+c[take]*(i-last[take]);
	last[take]=i;
	//cout<<sats<<"\n";
}
return sats;
}

pair <ll,ll> fun1(ll da,ll q){

ll x1=-1,x2=d;
FORR(i,da,0)
if(assigned[i]==q){
	x1=i;
	break;
}
FOR(i,da+1,d)
if(assigned[i]==q){
	x2=i;
	break;
}
return make_pair(x1,x2);
}

ll modify(ll da,ll q){
pair <ll,ll> a1=fun1(da,assigned[da]);
pair <ll,ll> a2=fun1(da,q);
ll z=ini;
ll f=assigned[da];
z-=v[da][f];
z-=c[f]*(da-a1.F)*(a1.S-da);
z+=v[da][q];
z+=c[q]*(da-a2.F)*(a2.S-da);
return z;
}

void change(ll da,ll q){
 	assigned[da]=q;
}





int main(){



    FAST
//	PRECISE


cin>>d;
FOR(i,0,26)
cin>>c[i];

FOR(i,0,d)
	FOR(j,0,26)
		cin>>v[i][j];

ve <ll> dummy(d);
FOR(i,0,d){
dummy[i]=rand()%26;
}
assigned=dummy;
ini=score();

ve <pair <ll,ll> > check;
FOR(i,0,d)
FOR(j,0,26)
check.pb({i,j});

	
ll tot=check.size();

ll it=1000000;
ll j=0;
while(it>0){
	it--;
	j=j%tot;
	ll x1=check[j].F;
	ll x2=check[j].S;
	ll z=modify(x1,x2);
	if(z>ini){
		ini=z;
		change(x1,x2);
	}
}


FOR(i,0,d)
cout<<assigned[i]+1<<"\n";

//cout<<ini<<endl;


return 0;
 }

Measured memory_bytes: 3840
#include<stdio.h>
#include<string.h>
int main(void){
    char str[100];
    int len,count=0;
    scanf("%s",str);
    len=strlen(str);
    for(int i=0;i<len;i++){
        if(str[i]=='U'||str[i]=='D')
            count++;
        else if(i==0&&str[i]=='R')
            count++;
        else if(i==1&&str[i]=='L')
            count++;
        else if(i%2==0&&str[i]=='R')
            count++;
        else if(i%2==1&&str[i]=='L')
            count++;
    }
    if(len==count)
        printf("Yes");
    else
        printf("No");
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#define EPS (1e-10)
using namespace std;

class Point{
public:
  double x,y;
  Point (double x = 0,double y = 0): x(x),y(y){}
  Point operator + (Point &p){ return Point(x+p.x,y+p.y);}
  Point operator - (Point &p){ return Point(x-p.x,y-p.y);}
  Point operator * (double k){ return Point(x*k,y*k);}
  bool operator < (const Point &p)const {
    if(x == p.x) return y < p.y;
    else return x < p.x;
  }
};

double cross(Point a,Point b){
  return a.x * b.y - a.y * b.x;
}

int main(){
  int i,j,n,x,y,k;
  Point p[100];
  vector<Point> convex,c2;
  while(1){
    cin >> n;
    if(n == 0) break;
    for(i=0;i<n;i++){
      scanf("%lf,%lf",&p[i].x,&p[i].y);
    }
    sort(p,p+n);

    convex.push_back(p[0]);
    convex.push_back(p[1]);

    j = 2;
    if(n > 3){
      for(i=2;i<n;i++){
	Point a = convex[j-1] - convex[j-2];
	Point b = p[i] - convex[j-2];
	while(cross(a,b) > EPS && j >= 2){ 
	  convex.pop_back();
	  j--;
	  if(j >= 2){
	    a = convex[j-1] - convex[j-2];
	    b = p[i] - convex[j-2];
	  }
	}
	convex.push_back(p[i]);
	j++;
      }
      
      c2.push_back(p[n-1]);
      c2.push_back(p[n-2]);
      k = 2;
      for(i=n-3;i>=0;i--){
	Point a = c2[k-1] - c2[k-2];
	Point b = p[i] - c2[k-2];
	while(cross(a,b) > EPS && k >= 2){
	  c2.pop_back();
	  k--;
	  if(k >= 2){
	    a = c2[k-1] - c2[k-2];
	    b = p[i] - c2[k-2];
	  }
	}
	c2.push_back(p[i]);
	k++;
      }
    }
    cout << n - (j + k - 2)<< endl;
    convex.clear();
    c2.clear();
  }
  return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import sys
N = int(input())

origin_x = 0
origin_y = 0
origin_t = 0

for i in range(0,N):
    t,x,y = map(int, input().split())
    distance_x = abs(x - origin_x)
    distance_y = abs(y - origin_y)
    sub_t = t - origin_t
    if distance_x + distance_y > sub_t:
        print('No')
        sys.exit()
    elif (sub_t - distance_x - distance_y) % 2 == 0:
        origin_x = x
        origin_y = y
        origin_t = t
    else:
        print('No')
        sys.exit()

print('Yes')

Measured memory_bytes: 3064
"use strict";
function body(ary){
    return ary.sort((a,b)=>a-b);
}

(function (){
    var s = require("fs").readFileSync("/dev/stdin", "utf8");
    var ary = s.split(' ').map(Number);

    var ans=body(ary);
    
    console.log(ans.join(' '));

})();


Measured memory_bytes: 15384
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int X=in(),Y=in();
	int sum=0;
	if(X==1) sum+=300000;
	else if(X==2) sum+=200000;
	else if(X==3) sum+=100000;
	if(Y==1) sum+=300000;
	else if(Y==2) sum+=200000;
	else if(Y==3) sum+=100000;
	if(X==1 && Y==1) sum += 400000;
	
	out(sum);
	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll ans = k;
    rep(i,n-1) ans *= (k-1);
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			int h = sc.nextInt();
			int w = sc.nextInt();
			int n = sc.nextInt();
			int line = w;
			int column = h;
			int ans = 0;
			int total = 0;
			while(total < n) {
				if(line >= column) {
					total += line;
					column--;
				} else {
					total += column;
					line--;
				}
				ans++;
			}
			System.out.println(ans);
		}

	}

}


Measured memory_bytes: 23124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atCocderCs
{
    class Program
    {
        const int MAX = 100000;

        static void Main(string[] args)
        {
            var Q = int.Parse(Console.ReadLine());
            var lst = new List<int[]>();
            for (int i = 0; i < Q; i++)
            {
                var arr = Console.ReadLine().Split(' ').Select((obj) => int.Parse(obj)).ToArray();
                lst.Add(arr);
            }
            var primeHash = new HashSet<int>(getPrimes());
            var dists = new int[MAX + 1];
            for (int i = 2; i <= MAX; i++)
                if (primeHash.Contains(i) && primeHash.Contains((i + 1) / 2))
                    dists[i] = dists[i - 1] + 1;
                else
                    dists[i] = dists[i - 1];

            for (int i = 0; i < lst.Count; i++)
            {
                var L = lst[i][0];
                var R = lst[i][1];
                Console.WriteLine(dists[R] - dists[L - 1]);
            }

        }

        static int[] getPrimes()
        {
            var npflgs = new bool[MAX + 1];
            for (int i = 3; i * i <= MAX; i += 2)
                if (!npflgs[i])
                    for (int j = i * i; j <= MAX; j += i)
                        npflgs[j] = true;

            var lst = new List<int>() { 2 };
            for (int i = 3; i <= MAX; i += 2)
                if (!npflgs[i])
                    lst.Add(i);

            return lst.ToArray();
        }
        
    }
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<long double> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());

    for (int i = 1; i < n; i++) {
        v[i] += v[i - 1];
        v[i] /= 2;
    }
    cout << fixed << setprecision(15) << v.back() << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
p = list(map(int, readline().split()))

q = sorted(p)
cnt = 0

for i in range(n):
    if p[i] != q[i]:
        cnt += 1

if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")


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

using namespace std;

typedef long long ll;

ll n;
ll a[200005];

int main()
{
    scanf("%lld", &n);
    for(ll i = 1; i < n; i++)
    {
        ll t;
        scanf("%lld", &t);
        a[t]++;
    }
    for(ll i = 1; i <= n; i++)
    {
        printf("%lld\n", a[i]);
    }
    return 0;
}


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

struct Edge { int to, id;};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
  int k = 1;
  rep(i,g[v].size()) {
    int u = g[v][i].to, ei = g[v][i].id;
    if (u == p) continue;
    if (k == c) ++k;
    ans[ei] = k; ++k;
    dfs(u,ans[ei],v);
  }
}

int main() {
  int n;
  cin >> n;
  g.resize(n);
  ans = vector<int>(n-1);
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back((Edge){b,i});
    g[b].push_back((Edge){a,i});
  }
  dfs(0);
  int mx = 0;
  rep(i,n) mx = max(mx, int(g[i].size()));
  cout << mx << endl;
  rep(i,n-1) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 2e2 + 7, M = 1e5 + 7;
const LL MOD = 1e9 + 7;

LL f[N][M], inv[M], tmp[M];
int a[N];

LL qpow(LL x, LL y){
	LL z = 1;
	while (y){
		if (y % 2) z = z * x % MOD;
		x = x * x % MOD;
		y /= 2;
	}
	return z;
}

int main(){

	int n, X;
	scanf("%d%d", &n, &X);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);

	inv[0] = 1;
	for (int i = 1; i <= n; i++) inv[i] = qpow(i, MOD - 2);


	LL t = 1;
	for (int i = 1; i <= n; i++) t = t * i % MOD;

	tmp[X] = inv[n];
	for (int i = 1; i <= n; i++){
		for (int j = 0; j < a[i]; j++){
			for (int k = j; k <= X; k += a[i]){
				f[i][j] = (f[i][j] + tmp[k]) % MOD;
			}
			//printf("%d %d %lld\n", i, j, f[i][j] * t % MOD);
		}
		//if (i == 2) printf("%lld^*^\n", tmp[5] * t % MOD);
		for (int j = 0; j < a[i]; j++){
			tmp[j] = (tmp[j] + f[i][j] * inv[n - i]) % MOD;
		}
	}
	LL ans = 0;
	
	for (int i = 0; i < a[n]; i++){
		ans = (ans + f[n][i] * i) % MOD; 
		//printf("%d %lld\n", i, f[n][i] * t % MOD);
	}
	for (int i = 1; i <= n; i++) ans = ans * i % MOD;

	printf("%lld", ans);
	return 0;
}
/*
f[i][x]   (i - 1)

f[j][x] = f[i][y] * 1 / (i - 1)   y % j = x

y = x   x + a[j]   x + 2 * a[j]
*/


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

int main() {
	int N;
	cin>>N;
	int x,y,b,p;
	int total;
	for (int i=0;i<N;++i){
		cin >>x>>y>>b>>p;
		total=x*b+y*p;
		if(b>=5&&p>=2)total=total*4/5;

		if(b<5&&p>=2)total=min(total,((5*x+p*y)*4)/5);
		if(b>=5&&p<2)total=min(total,((b*x+2*y)*4)/5);
		if(b<5&&p<2)total=min(total,((5*x+2*y)*4)/5);
		cout<<total<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        m: usize,
        h: [usize;n],
        edges: [(usize,usize);m]
    }

    let mut linked_list: Vec<Vec<usize>> = vec![Vec::new(); n];

    let mut visited = vec![false; n];

    for i in 0..m {
        linked_list[edges[i].0 - 1].push(edges[i].1 - 1);
        linked_list[edges[i].1 - 1].push(edges[i].0 - 1);
    }

    let mut ans = 0;

    for i in 0..n {
        let mut good = true;
        for j in 0..linked_list[i].len() {
            if h[i] <= h[linked_list[i][j]] {
                good = false;
            }
        }

        if good {
            ans += 1;
        }
    }

    println!("{:?}", ans);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


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

#define N 100000

int main(void){
    bool prime[N+1];
    prime[0]=prime[1]=!false;
    for (size_t i = 2; i*i <= N; i++)
    {
        if (!prime[i])
        {
            for (size_t j = 2; i*j <= N; j++)
            {
                prime[i*j]=!false;
            }
        }
    }
    int likeCnt[N+1];
    for (size_t i = 3; i <= N; i+=2)
    {
        likeCnt[i]=likeCnt[i-1];
        if (!prime[i]&&!prime[(i+1)/2]) likeCnt[i]++;
        likeCnt[i+1]=likeCnt[i];
    }
    /**************************************/
    int q;
    scanf("%d", &q);
    int l,r;
    for (size_t i = 0; i < q; i++)
    {
        scanf("%d%d", &l, &r);
        printf("%d\n", likeCnt[r] - likeCnt[l-1]);
    }
    return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>


int main(){
  char str[100000] = {};
  int n=0;
  int a[100000] = {};
  int cnt = 0;
  int i = 0;
  scanf(" %s",str);
  for(i=0;i<120000;i++){
    if(str[i] == '\0'){
      break;
    }
  }
  n = i;
  a[0] = 1;
  for(i=1;i<n;i++){
    if(str[i-1]==str[i]){
      a[cnt]++;
    }else{
      cnt++;
      a[cnt]++;
    }
  }
  
  /*for(i=0;i<=cnt;i++){
    printf("%d,",a[i]);
  }*/
  printf("%d",cnt);
  return 0;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N, M;
	cin >> N >> M;

	ll X[100001], Y[100001];
	rep(i, N) cin >> X[i];
	rep(i, M) cin >> Y[i];

	ll mod = 1e9 + 7;
	ll xtotal = 0;
	rep1(i, N - 1) {
		ll kari = ((X[i] - X[i - 1]) * i * (N - i)) % mod;
		xtotal = (xtotal + kari) % mod;
	}
	ll ytotal = 0;
	rep1(i, M - 1) {
		ll kari = ((Y[i] - Y[i - 1]) * i * (M - i)) % mod;
		ytotal = (ytotal + kari) % mod;
	}
	ll kotae = xtotal * ytotal % mod;

	co(kotae);

	Would you please return 0;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}

int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int h, w, n, ans=0;
	cin >>h >>w >>n;
	
	int mx = max(h,w);
	int mn = min(h,w);
	
	cout << (n + mx-1)/ mx <<"\n";
	return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int64_t> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  int64_t ans = 10000000000;
  for(int i=0; i<=N-K; i++){
    if(vec.at(i)*vec.at(i+K-1) >=0){
      int64_t a = abs(vec.at(i));
      int64_t b = abs(vec.at(i+K-1));
      int64_t x = max(a,b);
      ans = min(x,ans);
    }
    if(vec.at(i)*vec.at(i+K-1) < 0){
      int64_t a = abs(vec.at(i));
      int64_t b = abs(vec.at(i+K-1));
      int64_t x = max(a,b) + min(a,b)*2;
      ans = min(x,ans);
    }
  }  
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdlib.h>

using namespace std;
int vis[101];

int main(){
    int x,n;
    cin>>x>>n;
    if(n==0){
        cout<<x<<endl;
        return 0;
    }
    for(int i=0;i<n;++i){
        int tmp;
        cin>>tmp;
        vis[tmp]=1;
    }
    for(int i=0;i<=100;++i){
        if(x-i<=0){
            cout<<x-i<<endl;
            break;
        }
        if(!vis[x-i]){
            cout<<x-i<<endl;
            break;
        }else if(!vis[x+i]){
            cout<<x+i<<endl;
            break;
        }
    }
    return 0;
}

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

int main() {
  string w;
  char a = '0';
  bool k = true,jubge = true,b = false;
  cin >> w;
  sort(w.begin(),w.end());
  for(int i = 0; i < w.size(); i++){
    if(a == w.at(i)){
      swap(k,b);
    }else{
      a = w.at(i);
      swap(k,b);
      if(k){
        jubge = false;
        break;
      }
    }
  }
  if(w.size() == 1)
    jubge = false;
  if(jubge){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n=int(raw_input())
l=map(int,raw_input().split())

sm,avg,cost1,cost2=0,0,0,0

for el in l:
	sm+=el
avg1=sm//n
avg2=avg1+1

for el in l:
	cost1+=(avg1-el)**2
	cost2+=(avg2-el)**2

print min(cost2,cost1)



Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second

struct UnionFind{
  int n;
  vector<int> ran,p,cnt;
  UnionFind(){}
  UnionFind(int sz):n(sz),ran(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(ran[x]<ran[y]) swap(x,y);
    ran[x]+=ran[y];
    p[y]=x;
  }
  int sum(int x){
    return ran[find(x)];
  }
};

int n,m;
vector<int>s;
vector<P>v;
vector<P2>e;
map<int,int>M;

signed main(){
  while(cin>>n>>m,n){
    M.clear();
    v.clear();
    s.clear();
    e.clear();
    r(i,n){
      int a;
      cin>>a;
      v.push_back(P(a,i));
      s.push_back(a);
      M[i]=a;
    }
    r(i,m){
      int a,b,c;
      cin>>a>>b>>c;a--;b--;
      e.push_back(P2(a,P(b,c)));
    }
    sort(v.begin(),v.end());
    sort(s.begin(),s.end(),greater<int>());
    int MIN=-1;
    r(i,s.size()){
      vector<int>v1;
      vector<P2>e1;
      UnionFind U(n+7);
      r(j,n){
        if(M[j]>=s[i])v1.push_back(j);
      }
      r(j,m){
        if(M[e[j].F]>=s[i]&&M[e[j].S.F]>=s[i])U.unite(e[j].F,e[j].S.F);
      }
      if(U.sum(v1[0])!=v1.size()){
        MIN=s[i];
      }
    }
    int ans=0;
    UnionFind U(n+7);
    vector<P2>vv;
    if(MIN==-1)MIN=1e9;
    r(i,s.size()){
      if(MIN!=-1&&s[i]>=MIN)continue;
      vv.clear();
      r(j,m){
        if(M[e[j].F]>=s[i]&&M[e[j].S.F]>=s[i]){
          int A=e[j].F,B=e[j].S.F;
          vv.push_back(P2(e[j].S.S,P(A,B)));
        }
      }
      sort(vv.begin(),vv.end());
      r(j,vv.size()){
        int A=vv[j].S.F,B=vv[j].S.S;
        if(!U.same(A,B)){
          U.unite(A,B);
          ans+=vv[j].F;
        }
      }
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 1005;

char ans3[12][12] = {"aa.", "..a", "..a"};
char ans4[12][12] = {"aacd", 
					 "bbcd",
					 "dcaa",
					 "dcbb"};

char ans5[12][12] = {"aabc.", 
					 "..bcd", 
					 "iij.d", 
					 "n.jaa", 
					 "nkkbb"};

char ans7[12][12] = {"aade...", 
					 "bbde...", 
					 "ccffg..", 
					 "..i.gee", 
					 "..ihhdd", 
					 "....cba", 
					 "....cba"};

char ans10[12][12] = {"aacd......", 
					  "bbcd......", 
					  "..eeab....", 
					  "..ffab....", 
					  "ef..cc....", 
					  "ef..dd....", 
					  "......aacd", 
					  "......bbcd", 
					  "......dcaa", 
					  "......dcbb"};

int n;
char ans[N][N];

void put(char (*T)[12], int x, int d) {
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < d; j++) {
			ans[x + i][x + j] = T[i][j];
		}
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			ans[i][j] = '.';
		}
	}
	if (n == 1 || n == 2) {
		puts("-1");
		return 0;
	} else if (!(n % 3)) {
		for (int i = 0; i < n; i += 3)
			put(ans3, i, 3);	
	} else if (n == 4) {
		put(ans4, 0, 4);
	} else if (n == 5) {
		put(ans5, 0, 5);
	} else if (n == 7) {
		put(ans7, 0, 7);
	} else if (n == 10) {
		put(ans10, 0, 10);
	} else if (n == 11) {
		put(ans4, 0, 4);
		put(ans7, 4, 7);
	} else {
		int c4 = 0, t = 0;
		while ((n - c4 * 4) % 5)
			c4++;
		for (int i = 0; i < c4; i++, t += 4)
			put(ans4, t, 4);
		while (t < n)
			put(ans5, t, 5), t += 5;
	}
	for (int i = 0; i < n; i++)
		puts(ans[i]);
	return 0;
}


Measured memory_bytes: 2176
/*  ex5_3
    takafumi_ueki*/
#include <stdio.h>
    int main(void){
        int i,j,length,width;
        int row[100]={0};
        int col[100]={0};
        char field[100][100];
        //縦と横の長さを受け取る
        scanf("%d %d",&length,&width);
        //'.'か'#'かを受け取る
        for(i=0;i<length;i++){
            for(j=0;j<width;j++){
                scanf(" %c",&field[i][j]);
            }
        }
        //列ごとに'.'が含まれているかどうかを調べる
        //もし含まれていたらrow[i]が1になる
        for(i=0;i<length;i++){
            for(j=0;j<width;j++){
                if(field[i][j]=='#'){
                    row[i]=1;
                    break;
                }
            }
        }
        //次に行ごとに'.'が含まれていないか調べる
        for(j=0;j<width;j++){
            for(i=0;i<length;i++){
                if(field[i][j]=='#'){
                    col[j]=1;
                    break;
                }
            }
        }
        //もし '.'がひとつでも含まれていたらその行、列は'#'と'.'で構成されているので、書き出すようにする
        for(i=0;i<length;i++){
            for(j=0;j<width;j++){
                if(row[i]==1&&col[j]==1){
                    printf("%c",field[i][j]);
                }
            }
            printf("\n");
        }
        return 0;
    }

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

int main(){
	int n,k;
	cin >> n >> k;
	vector<string> s(n);
	for(int i = 0; i < n; i++)
		cin >> s[i];
	sort(s.begin(),s.end());
	for(int i =0 ; i < n-1;i++)
		cout << s[i];
	cout << s[n-1] << endl;
	
}

Measured memory_bytes: 256