akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

int main() {
	intt N; std::cin >> N;
	std::vector<intt> s(N);
	intt total = 0;
	for (auto& r : s) {
		std::cin >> r;
		total += r;
	}
	if (total % 10 != 0) {
		std::cout << total << std::endl;
		return 0;
	}
	else {
		std::sort(s.begin(), s.end());
		bool flag = false;
		int total2;
		for (int i = 0; i < N; ++i) {
			total2 = total - s[i];
			if (total2 % 10 != 0) {
				flag = true;
				break;
			}
		}
		if (flag == true) {
			std::cout << total2 << std::endl;
		}
		else
			std::cout << 0 << std::endl;
	}
}

Measured memory_bytes: 3640
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var (
		n, k int
		s    string
	)
	fmt.Scan(&n, &s, &k)

	var wr = bufio.NewWriter(os.Stdout)

	for i := 0; i < n; i++ {
		if s[i] != s[k-1] {
			wr.WriteString("*")
		} else {
			wr.WriteString(string(s[i]))
		}
	}
	wr.WriteString("\n")
	wr.Flush()
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v1(100001), v2(100001);
  for (int i = 0; i*2 < n; i++) {
    int a;
    cin >> a;
    v1[a]++;
    cin >> a;
    v2[a]++;
  }
  int v1max = 0, v2max = 0;
  int index1 = -1, index2 = -1;
  int v12 = 0, v22 = 0;
  int i12 = -1, i22 = -1;
  for (int i = 0; i < 100001; i++) {
    if (v1max <= v1[i]) {
      v12 = v1max;
      i12 = index1;
      v1max = v1[i];
      index1 = i;
    } else if (v12 <= v1[i]) {
      v12 = v1[i];
    }
    if (v2max <= v2[i]) {
      v22 = v2max;
      i22 = index2;
      v2max = v2[i];
      index2 = i;
    } else if (v22 <= v2[i]) {
      v22 = v2[i];
    }
  }
  int ans = 0;
  if (index1 == index2) {
    ans = min(n - v1max - v22, n - v2max - v12);
  } else {
    ans = n - v1max - v2max;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3992
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    vector<int> ignoreOffset;
    string ans = "AC";

    // 1
    if (S.at(0) != 'A') ans = "WA";
    if (S.at(0) == 'A') ignoreOffset.push_back(0);

    // 2
    int count = 0;
    int offset = 0;
    rep(i, S.size()) {
        if (2 <= i && i <= S.size() - 2) {
            if (S.at(i) == 'C') {
                count++;
                offset = i;
            }
        }
    }
    if (count != 1) ans = "WA";
    if (count == 1) {
        ignoreOffset.push_back(offset);
    }

    // 3
    if (ans == "AC") {
        rep(i, S.size()) {
            if (S.at(i) < 'a' || 'z' < S.at(i)) {
                bool isOk = false;
                for (int offset : ignoreOffset) {
                    if (i == offset) isOk = true;
                }
                if (!isOk) ans = "WA";
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  long long a,b,mi,ma;
  while(cin>>a>>b){
    ma=max(a,b);
    mi=min(a,b);
    while(1){
      if(ma%mi==0){
	cout<<mi<<" "<<a*b/mi<<endl;
	break;
      }
      swap(ma,mi);
      mi=mi%ma;
    }
  }
}

Measured memory_bytes: 3004
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define f(i,n)          for(int i=0;i<n;i++)
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout << fixed; cout << setprecision(x); cout << y;
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
typedef tree<pii, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
const int N = 1e6 + 3;
int32_t main()
{
	g_b();
	int n; cin >> n;
	int ans = 1;
	if (n % 2 == 0 || n % 5 == 0)
	{
		cout << "-1";
		return 0;
	}
	int x = 7 % n;
	while (x != 0)
	{
		x = x * 10 + 7;
		x = x % n;
		ans++;
	}

	cout << ans;
	return 0;

}



Measured memory_bytes: 3596
// prakhsri_
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<time.h>
using namespace std;
#define ll long long int
#define pb push_back
#define fi first i
#define se second
#define mod 1000000007
#define PI 3.1415926535897

int main(){
    int a[5];
    int i;
    for(i=0;i<5;i++){
        cin>>a[i];
        if(a[i]==0)
        {
            cout<<i+1;
            return 0;
        }
    }
}   


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vvi num(n,vi(n));
    int sz = 0;
    rep(i,n) rep2(j,i+1,n) num[i][j] = num[j][i] = sz++;
    vvi G(sz);
    vi in(sz,0);
    rep(i,n) {
        vi a(n-1);
        cin >> a;
        rep(j,n-1) a[j]--;
        rep(j,n-2) {
            G[num[i][a[j]]].pb(num[i][a[j+1]]);
            in[num[i][a[j+1]]]++;
        }
    }
    queue<int> q;
    rep(i,sz) if(!in[i]) q.push(i);
    int ans = 0;
    while(q.size()) {
        ans++;
        vi v;
        while(q.size()) {
            int now = q.front();
            q.pop();
            for(int i : G[now]) {
                if(--in[i] == 0) v.pb(i);
            }
        }
        for(int i : v) q.push(i);
    }
    rep(i,sz) if(in[i]) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 33536
#!/usr/bin/env python3 

[x, y] = list(map(int, input().split()))


if x % y == 0:
	res = -1
else:
	current = x
	while (1):
		current += x
		if (current > 10**18):
			res = -1
			break
		if (current % y != 0):
			res = current
			break
		else:
			continue

print(res)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define N 200000

int main(void){
    short int *x = (short int*)malloc(sizeof(short int)*N);
    short int *y = (short int*)malloc(sizeof(short int)*N);
    int flag = 0;
    for(int i=0; i<=N; i++){
        x[i] = 0;
        y[i] = 0;
    }

    int n, m;
    scanf("%d %d", &n, &m);

    int tempx, tempy;
    for(int i=0;i<=m;i++){
        scanf("%d %d", &tempx, &tempy);
        if(tempx==1){
            x[tempy] = 1;
        }
        if(tempy==n){
            y[tempx] = 1;
        }
    }

    for(int i=0; i<=n;i++){
        if(x[i]==1){
            if(y[i]==1){
                flag = 1;
                break;
            }
        }
    }

    if(flag==1){
        printf("POSSIBLE");
    }else{
        printf("IMPOSSIBLE");
    }
}

Measured memory_bytes: 896
#define others
#ifdef poj
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#endif // poj
#ifdef others
#include <bits/stdc++.h>
#endif // others
//#define file
#define all(x) x.begin(), x.end()
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int dcmp(double x) {
    if(fabs(x)<=eps) return 0;
    return (x>0)?1:-1;
};
typedef long long LL;
typedef unsigned long long ULL;
void umax(int &a, int b) {
    a = max(a, b);
}
void umin(int &a, int b) {
    a = min(a, b);
}

void file() {
    freopen("a.in", "r", stdin);
//    freopen("1.txt", "w", stdout);
}

int main() {
//    file();
    LL n, v[111111];
    cin >> n;
    for(int i =1; i <= n; i++) {
        scanf("%lld", &v[i]);
    }
    if(v[n] != 2) {
        puts("-1");
        return 0;
    }
    LL ans1 = v[n], ans2 = v[n] * 2 - 1;
    for(int i = n - 1; i >= 1; i--) {
        ans1 += v[i] - 1;
        ans1 /= v[i];
        ans2 /= v[i];
        ans1 *= v[i];
        ans2 *= v[i];
        ans2 += v[i] - 1;
        if(ans1 > ans2) {
            puts("-1");
            return 0;
        }
    }
    cout<<ans1<<" "<<ans2<<endl;
    return 0;
}

/*
624564646487
664212112111
*/


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

int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int ans=0;
    if(K <= A) ans=K;
    else if(K <= A+B) ans=A;
    else if(K <= A+B+C) ans=A-(K-A-B);

    cout << ans << endl;

    return 0;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 smod = 998244353ll;
//const i64 inf = 1'000'000'000'000'000'000ll + 7;
const i64 inf = 1'000'000'007;

const long double eps = 1e-8;

const i64 MAXN = 200'000 + 5;


int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);

    i64 l, r, d;
    cin >> l >> r >> d;

    l = l / d + (l % d ? 1 : 0);
    r = r / d;
    cout << max(0ll, r - l + 1) << endl;

    return 0;
}


Measured memory_bytes: 3664
#include <iostream>

#define FOR(i,a,b) for(long long int i =(a); i <(b);i++)
#define REP(i,N)   FOR(i,0,N)
#define debug(x)   cout << #x << " = " << x << endl;

using namespace std;

int main(void){

    int N;
    cin >> N;

    if(N >= 1200){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }

    return 0;
}


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

int main() {
  string s,t;
  cin >> s >> t;
  int a;
  a = s.size();
  int count = 0;
  for(int i = 0; i < a; i++){
    if(s.at(i) != t.at(i) ){
      s.at(i) = t.at(i);
      count ++;
    }
  }
  cout << count << endl;
      
}

Measured memory_bytes: 3916
#include<iostream>
#include<string>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define minimize(a,b) (a>(b)?a=(b),1:0)
#define maximize(a,b) (a<(b)?a=(b),1:0)
#define ceil(a,b) (((a)+(b)-1)/(b))
#define yn(i) ((i)?"Yes":"No")
#define chmin(a,b) (a>(b)?a=(b),1:0)
#define abs(n) max((n),-(n))
#define dist(a,b) max((a)-(b),(b)-(a))
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}




string key="keyence";

void add(char m,string s,set<string> st){
  int n=s.size();
  rep(i,n){
    if(s[i]!=m) continue;
    string t;
    repa(j,i,n){
      t.push_back(s[j]);
      st.insert(t);
    }
  }
}

int gcd(int a,int b){
  return b?gcd(b,a%b):a;
}

int main(){
  li n; cin >>n;
  li m; cin >>m;
  rep(i,4){
    li a; cin >>a;
    minimize(m,a);
  }
  print(ceil(n,m)+4);
  
}





Measured memory_bytes: 3628
//in the name of God
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll n,k,ans;

int main(){
    cin>>n>>k;
    ll t=(n/k);
    ans=t*t*t;
    if((k&1)==0){
        if(n%k >=k/2) t++;
        ans+=t*t*t;
    }
    cout<<ans<<endl;
    return 0;
}


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

char data[9][9];
char out[9][9]; //出力用

void rotation90(){

  for(int i=0; i<8; i++) {
    for(int j=0; j<8; j++) {
      out[i][j] = data[7-j][i];
    }
  }

  for(int i=0; i<8; i++) {
    for(int j=0; j<8; j++) {
      cout<< out[i][j];
      data[i][j] = out[i][j];
    }
    cout<< endl;
  }

}

int main(){
 
  for(int i=0; i<8; i++) {
    for(int j=0; j<8; j++) {
      cin>> data[i][j];
    }
  }

  for(int i=1; i<4; i++) {
    cout<< 90*i<< endl;
    rotation90();
  }

}

Measured memory_bytes: 1140
#include<bits/stdc++.h>
 
#define ll long long int
#define Y printf("YES\n")
#define N printf("NO\n")
#define pb push_back
#define tp make_tuple
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pr(a) printf("%lld\n",a)
#define r0 return 0
#define pi acos(-1)
 
using namespace std;

int main()
{
	ll n,m,i,j,k,l,r,x,y,z,t;
	
	ll a,b,c,d;
	
	cin>>a>>b>>c>>d;
	
    x=max(a*c,a*d);
    
    x=max(x,b*c);
    
    x=max(x,b*d);
    
    cout<<x<<endl;
}

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

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

int main(){
    int N;
    while(cin >> N, N != 0){
        vector<pair<int, int> > v;
        v.push_back(make_pair(0, 0));
        for(int i=1;i<N;++i){
            int n, d;
            cin >> n >> d;
            v.push_back(make_pair(v[n].first+dx[d], v[n].second+dy[d]));
        }
        int xmin = 0, ymin = 0, xmax = 0, ymax = 0;
        for(auto e : v){
            xmin = min(xmin, e.first);
            ymin = min(ymin, e.second);
            xmax = max(xmax, e.first);
            ymax = max(ymax, e.second);
        }
        cout << abs(xmax - xmin) + 1 << " " << abs(ymax - ymin) + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3088
package main

import (
        "fmt"
        "strings"
)

func main() {
        var n int
        var s, t string
        fmt.Scan(&n)
        fmt.Scan(&s, &t)
        var ary []string
        for i := 0; i < n; i++ {
                ary = append(ary, s[i:i+1])
    ary = append(ary, t[i:i+1])
        }
  res := strings.Join(ary, "")
        fmt.Println(res)
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main(){
    int a,b,c;
cin>>a>>b>>c;
if(a>=b&&b>=c){cout<<a-c<<endl;}
else if (a>=c&&c>=b){cout<<a-b<<endl;}
else if(b>=a&&a>=c){cout<<b-c<<endl;}
else if(b>=c&&c>=a){cout<<b-a<<endl;}
else if(c>=a&&a>=b){cout<<c-b<<endl;}
else{cout<<c-a<<endl;}
}


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

int main() {
  int N;
  cin >> N;
  int count=0;
  int b=1;
  vector<int> a(N,0);
    for(int i=0;i<N;i++){
      cin >> a.at(i);
    }
    for(int j=0;j<N;j++){
      if(a.at(b-1) != 2){
        b=a.at(b-1);
        ++count;
      }
      else if(a.at(b-1)==2){
        ++count;
        break;
      }
    }
    if(a.at(b-1)==2){
      cout << count << endl;
    }
      else if(a.at(b-1) != 2){
        cout << "-1" << endl;
      }
}  

Measured memory_bytes: 640
n, m = map(int, input().split())

A = []
B = []
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

C = zip(A, B)
C = sorted(C)
A, B = zip(*C)

total_price = 0
total_num = 0
for i in range(n):
    if total_num < m:
        buy = min(B[i], m - total_num)
        total_num += buy
        total_price += buy*A[i]
    else:
        break
print(total_price)

Measured memory_bytes: 75352
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  if(a==b)cout<<"EQUAL"<<endl;
  else if(a.size()!=b.size())cout<<(a.size()<b.size()?"LESS":"GREATER")<<endl;
  else cout<<(a<b?"LESS":"GREATER")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<queue>
#define rep(i,m) for(int i=0;i<m;i++)
typedef long ll;
using namespace std;

	int gcd(int a,int b) {
		if (b==0) return a;
		return gcd(b, a%b);
	}
	int main() {
		int n;
        cin >> n;
		vector<int> a(n);
		rep(i, n)cin >> a[i];

		int gc = a[0];
		for (int i=1;i<n;i++) {
			gc=gcd(gc, a[i]);
		}
		cout << gc << endl;
	}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

int h,w,c;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int count(vector<vector<int>> &v){
    int res=0;
    queue<P> q;
    q.push(P(0,0));
    while(!q.empty()){
        P p=q.front();q.pop();
        if(v[p.first][p.second]!=c) continue;
        res++;
        v[p.first][p.second]=-1;
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i],ny=p.second+dy[i];
            if(nx<0 || h<=nx || ny<0 || w<=ny) continue;
            if(v[nx][ny]!=c) continue;
            q.push(P(nx,ny));
        }
    }
    return res;
}

void paint(vector<vector<int>> &v, int col){
    int base=v[0][0];
    if(base==col) return;
    queue<P> q;
    q.push(P(0,0));
    while(!q.empty()){
        P p=q.front(); q.pop();
        if(v[p.first][p.second]!=base) continue;
        v[p.first][p.second]=col;
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i],ny=p.second+dy[i];
            if(nx<0 || h<=nx || ny<0 || w<=ny) continue;
            if(v[nx][ny]!=base) continue;
            q.push(P(nx,ny));
        }
    }
    return ;
}

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

    while(cin>>h>>w>>c,h||w||c){
        c--;
        vector<vector<int>> v(h,vector<int>(w));
        for(int i=0;i<h;i++) for(int j=0;j<w;j++){
            cin>>v[i][j]; v[i][j]--;
        }
        int res=0;
        for(int p=0;p<6;p++){
            for(int q=0;q<6;q++){
                for(int r=0;r<6;r++){
                    for(int i=0;i<6;i++){
                        for(int j=0;j<6;j++){
                            vector<vector<int>> cp=v;
                            paint(cp,p);
                            paint(cp,q);
                            paint(cp,r);
                            paint(cp,i);
                            paint(cp,j);
                            res=max(res,count(cp));
                        }
                    }
                }
            }
        }
        cout<<res<<endl;
    }
}


Measured memory_bytes: 3100
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#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 chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
const int IMAX = 200010;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
	constexpr unko() : fac(), ifac(), inv() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
		inv[0] = 1;
		rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
	}
	int comb(int A, int B) {
		return ll(fac[A]) * ifac[B] % mod * ifac[A - B] % mod;
	}
} f;

int N;
const int VN = 200000;
int to[VN * 2 + 2], ne[VN * 2 + 2], he[VN + 1];
int n[VN + 1];
void dfs(int v) {
	n[v]++;
	int mae = 0;
	for (int i = he[v]; i; i = ne[i]) {
		int t = to[i];
		if (n[t]) {
			if (mae) ne[mae] = ne[i];
			else he[v] = ne[i];
		}
		else {
			dfs(t);
			n[v] += n[t];
		}
		mae = i;
	}
}
void dfs2(int v) {
	for (int i = he[v]; i; i = ne[i]) {
		int t = to[i];
		n[t] = ll(n[v]) * n[t] % mod * f.inv[N - n[t]] % mod;
		dfs2(t);
	}
}

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

	
	cin >> N;
	int k = 2;
	rep1(i, N - 1) {
		int a, b;
		cin >> a >> b;

		to[k] = b;
		ne[k] = he[a];
		he[a] = k++;
		to[k] = a;
		ne[k] = he[b];
		he[b] = k++;
	}
	dfs(1);
	ll tmp = 1;
	rep1(i, N) tmp = (tmp * n[i]) % mod;
	n[1] = modpow(tmp, mod - 2) * f.fac[N] % mod;
	for (int i = he[1]; i; i = ne[i]) {
		int t = to[i];
		n[t] = ll(n[1]) * n[t] % mod * f.inv[N - n[t]] % mod;
		dfs2(t);
	}
	rep1(i, N) co(n[i]);

	Would you please return 0;
}

Measured memory_bytes: 7040
import sys
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())

H,W,D = Is()
d = dict()
for i in range(H):
    s = Is()
    for j,e in enumerate(s):
        d[e] = (i,j)
m = [0]*(H*W+1)
for i in range(D+1,H*W+1):
    m[i] = m[i-D] + abs(d[i-D][0] - d[i][0]) + abs(d[i-D][1] - d[i][1])

Q = I()
for q in range(Q):
    l,r = Is()
    print(m[r]-m[l])


Measured memory_bytes: 22812
// 2018.5.1 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int partition(int *a, int lo, int hi)
{
	int i, j, x, t;

	x = a[hi], i = lo-1;
	for (j = lo; j < hi; j++) {
		if (a[j] <= x) i++, t = a[i], a[i] = a[j], a[j] = t;
	}
	t = a[++i], a[i] = a[hi], a[hi] = t;
	return i;
}

int a[100002];

int main()
{
	int n, i, k;
	
	n = in(); for (i = 0; i < n; i++) a[i] = in();
	k = partition(a, 0, n-1);
	printf((!k? "[%d]": "%d"), a[0]);
	for (i = 1; i < n; i++) {
		putchar(' ');
		printf((k==i? "[%d]": "%d"), a[i]);
	}
	putchar('\n');
	return 0;
}





Measured memory_bytes: 2080
import java.util.*;

public class Main {
  public static void main(String[] args) {
  	Scanner scanner = new Scanner(System.in);
    // 値の入力
    int number = scanner.nextInt();
    
    // N人の子供それぞれのキャンディーを合計していく
    int sum = 0;
    for(int i = 1; i <= number; i++) {
      sum += i; 
    }
    
    // キャンディーの合計数を出力
    System.out.println(sum);
  }
}

Measured memory_bytes: 35780
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=1000000000000001;
const double PI=3.141592653589;


int main(){
  int d,g; cin>>d>>g;
  vector<P> p(d);
  rep(i,d){
    int a,b; cin>>a>>b;
    p[i]={a,b};
  }

  int ans=100009;
  for(int bit=0;bit<(1<<d);bit++){
    int c=0;
    int sum=0;
    // cout<<"bit "<<bitset<8>(bit)<<endl;
    rep(i,d){
      int chek=(1<<i)&bit;
      if(chek!=0){
        c+=p[i].first;
        sum+=(i+1)*100*p[i].first+p[i].second;
      }
    }
    if(sum>=g){
      ans=min(ans,c);
      continue;
    }
    for(int i=d-1;i>=0;i--){
      int chek=(1<<i)&bit;
      if(chek!=0) continue;
      bool z;
      rep(j,p[i].first){
        c++;
        sum+=(i+1)*100;
        if(sum>=g){
          ans=min(ans,c);
          z=1;
          break;
        }
      }
      if(z)
      break;
    }
    // cout<<"sum "<<sum<<" c "<<c<<endl;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e3+10;
int dp[maxn][maxn];

int main() {
	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	int x,y;
	int x3,y3,x4,y4;
	x=x2-x1;
	y=y2-y1;
	x3=x2-y;
	y3=y2+x;
	x4=x3-x;
	y4=y3-y;
	cout<<x3<<" "<<y3<<" ";
	cout<<x4<<" "<<y4;
	return 0;
}


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

signed main() {

    long long n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    long long mi = min ( a, min ( b, min ( c, min ( d, e ) ) ) );
    cout << 4 + ( n + mi - 1 ) / mi << endl;

    return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  string s;cin>>s;
  int q;cin>>q;
  deque<char> dq;
  for(int i=0;i<s.size();i++){
    dq.push_back(s[i]);
  }
  bool rev=0;
  while(q--){
    int t;cin>>t;
    if(t==1){
      rev=!rev;
    }else{
      int f;char c;cin>>f>>c;
      if((!rev && f==1) || (rev && f == 2)){
        dq.push_front(c);
      }else{
        dq.push_back(c);
      }
    }
  }
  for(int i=0;i<dq.size();i++){
    if(rev){
      cout<<dq[dq.size()-i-1];
    }else{
      cout<<dq[i];
    }
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 976
while True:
    try:
        a, b, c, d, e, f = map(float, input().split())
        x = (e * c - f * b) / (e * a - d * b) + 0
        y = (d * c - f * a) / (d * b - e * a) + 0
        print('{0:.3f} {1:.3f}'.format(x, y))
    except EOFError:
        break


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

int main() {
    int n,i;
    ll s=0,t=0,mx=LONG_LONG_MAX,ab;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    for(i=0;i<n-1;i++)
    {
        t+=a[i];
        ab=s-t-t;
        if(ab<0)
        ab=ab*(-1);
        mx=min(mx,ab);
    }
    cout<<mx;
    
    
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	long long n, i, j, k, x, ans = 0;

	cin >> n;
	vector<long long> a(n);
	cin >> a[0];
	x = a[0] / 2;
	ans += x;
	a[0] -= x * 2;

	for (i = 1; i < n; i++) {
		cin >> a[i];

		if (i > 0) {
			x = min(a[i], a[i - 1]);
			ans += x;
			a[i] -= x;
			a[i - 1] -= x;
		}

		x = a[i] / 2;
		ans += x;
		a[i] -= x * 2;
	}

	cout << ans << "\n";

	return 0;
}




Measured memory_bytes: 1400
#include  <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
typedef long long ll;
using namespace std;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll cnt=0;
    rep(i,n)
    {
        ll temp;
        cin>>temp;
        if(temp>=k)
            cnt++;
    }
    cout<<cnt;
}


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

using namespace std;

class ModInt{
private:
  long long number;

public:
  static constexpr long long mod = 1'000'000'007;

  constexpr ModInt(const ModInt& x) : number(x.number){};

  constexpr ModInt(const long long number = 0) : number((mod + number) % mod){}

  constexpr long long get() const{
    return number;
  }

  constexpr ModInt& operator=(const ModInt& rhs) &{
    number = rhs.number;
    return *this;
  }

  constexpr ModInt operator+() const{
    return ModInt(*this);
  }

  constexpr ModInt operator-() const{
    return ModInt(mod - number);
  }

  constexpr ModInt& operator+=(const ModInt& rhs){
    number += rhs.number;
    if(number >= mod) number -= mod;
    return *this;
  }

  constexpr ModInt& operator-=(const ModInt& rhs){
    number -= rhs.number;
    if(number < 0) number += mod;
    return *this;
  }

  constexpr ModInt& operator*=(const ModInt& rhs){
    (number *= rhs.number) %= mod;
    return *this;
  }

  constexpr ModInt& operator/=(const ModInt& rhs){
    (*this) *= rhs.inverse();
    return *this;
  }

  constexpr ModInt inverse() const{
    long long a = number, m = mod, u = 1, v = 0;

    while(m){
      long long t = a / m;
      a -= t * m;
      u -= t * v;

      //swap a, m
      a ^= m;
      m ^= a;
      a ^=m;

      //swap u, v
      u ^= v;
      v ^= u;
      u ^= v;
    }

    return ModInt(u);
  }

  constexpr ModInt& operator++(){
    return *this += 1;
  }

  constexpr ModInt& operator--(){
    return *this -= 1;
  }

  constexpr ModInt operator++(int x){
    ModInt ret = *this;
    ++(*this);
    return ret;
  }

  constexpr ModInt operator--(int x){
    ModInt ret = *this;
    --(*this);
    return ret;
  }
};

constexpr ModInt operator+(const ModInt& lhs, const ModInt& rhs){
  return ModInt(lhs) += rhs;
}

constexpr ModInt operator-(const ModInt& lhs, const ModInt& rhs){
  return ModInt(lhs) -= rhs;
}

constexpr ModInt operator*(const ModInt& lhs, const ModInt& rhs){
  return ModInt(lhs) *= rhs;
}

constexpr ModInt operator/(const ModInt& lhs, const ModInt&rhs){
  return ModInt(lhs) /= rhs;
}

constexpr ModInt operator^(const ModInt& lhs, const int& rhs){
  long long b = lhs.get(), e = rhs, y = 1, mod = lhs.mod;
  bool inv = e < 0;
  if(inv) e = -e;

  while(e){
    if(e & 1) (y *= b) %= mod;

    (b *= b) %= mod;
    e >>= 1;
  }

  return (inv ? ModInt(y).inverse() : ModInt(y));
}

std::istream& operator>>(std::istream& is, ModInt& x){
  long long in;
  is >> in;
  x = in;
  return is;
}

std::ostream& operator<<(std::ostream& os, const ModInt& x){
  os << x.get();
  return os;
}


int main(){
  int N;
  cin >> N;
  
  int a[N][N];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cin >> a[i][j];
    }
  }
  
  vector<ModInt> dp((1 << N), 0);
  dp[0] = 1;
  for(int s = 1; s < (1 << N); s++){
    int i = __builtin_popcount(s);
    for(int j = 0; j < N; j++){
      if((s & (1 << j)) && a[i - 1][j]){
        dp[s] += dp[s ^ (1 << j)];
      }
    }
  }
  
  cout << dp[(1 << N) - 1] << endl;
  
  return 0;
}

Measured memory_bytes: 16640
N, M = map(int, input().split())
check = []
for i in range(N):
    a, b = map(int, input().split())
    check.append((a,b))
    
check = sorted(check)

flag = 0
ans = 0
for i,j in enumerate(check):
    flag += j[1] 
    ans += j[0] * j[1]
    if flag >= M:
        print(ans -  check[i][0] * (flag - M))
        break

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  using pll = pair<ll, ll>;
  vector<pll> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i].first;
  }
  for (int i = 0; i < n; i++) p[i].second = i, p[i].first = -p[i].first;
  sort(p.begin(), p.end());
  ll ans = 0;
  set<int> s;
  for (int i = 0; i < n; i++) {
    auto it = s.lower_bound(p[i].second);
    ll ll = -1, lr = -1, rl = n, rr = n;
    if (it != s.end()) {
      rl = *it;
      it++;
      if (it != s.end()) {
        rr = *it;
      }
      it--;
    }
    if (it != s.begin()) {
      it--;
      lr = *it;
      if (it != s.begin()) {
        it--;
        ll = *it;
      }
    }
    ans += ((lr - ll) * (rl - p[i].second) + (rr - rl) * (p[i].second - lr)) * (-p[i].first);
    s.insert(p[i].second);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6528
/**
 * Title: D - Bouquet
 * Url: https://atcoder.jp/contests/abc156/tasks/abc156_d
 */
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
#include<functional>
#include<sstream>
#include<iomanip>

using namespace std;

#define ll long long

#define MOD 1000000007

// ModPow 
// 繰り返し二乗法を利用し, 高速に a^n% mod p を計算する
// 計算量：O(log(n)) 底は2
long long ModPow(long long  a, long long n, long long p) {
    int res = 1;
    if (n==1) return a % p;
    if (n % 2 == 1) return (a * ModPow(a, n-1, p)) %p;
    long long t = ModPow(a, n/2, p);
    return (t * t) % p;
}

// ExtGCD
// 拡張ユークリッド控除法を使った最大公約数計算
// ax + by = gcd(a, b) を満たす (x, y) を格納する.
// 計算量：O(log(max(a, b))) 底は2
long long ExtGCD(long long a, long long b, long long &x, long long &y) {
    if(b==0) {
        x = 1;
        y = 0;
        return a;
    }
    long long r = a%b;
    long long d = ExtGCD(b, r, y, x);
    y -= a/b * x;
    return d;
}

// ModInvExtGCD
// 拡張ユークリッド控除法を利用した a の逆元計算
// 利用条件：特になし
// 計算量：O(log(p)) 底は2
long long ModInvExtGCD(long long a, long long p) {
    long long x, y;
    long long d = ExtGCD(a, p, x, y);
    if (x < 0) x += p;
    return x;
}

// ModComb
// nCk mod p 計算
// 計算量：O(k+k*log(p))
long long ModComb(long long n, long long k, long long p) {
    long long count = 0;
    long long res = 1;
    for(long long i=n; i>=n-k+1; i--) {
        res *= i;
        res %= p;
        count++;
    }
    for(long long i=1; i<=k; i++) {
        res *= ModInvExtGCD(i, p);
        res %= p;
        count++;
    }
    return res;
}

int main() {

    ll n, a, b;

    cin >> n >> a >> b;

    ll ans = ModPow(2, n, MOD) - 1 - ModComb(n, a, MOD) - ModComb(n, b, MOD);
    while(ans < 0) {
        ans += MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
S = input()
tap = 'Yes'
for i, j in enumerate(S):
  if j in ('U', 'D'):
    continue
  elif (i + 1) % 2 == 0 and j == 'L':
    continue
  elif (i + 1) % 2 == 1 and j == 'R':
    continue
  else:
    tap = 'No'
    break
    
print(tap)

Measured memory_bytes: 2940
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt() - 1;
		}
		long[] sum = new long[n];
		for (int i = 0; i < n; i++) {
			sum[a[i]]++;
		}
		long ans = 0;
		for (int i = 0; i < n; i++) {
			if (sum[i] >= 2) {
				ans += sum[i] * (sum[i] - 1) / 2;
			}
		}
		long[] anss = new long[n];
		for (int i = 0; i < n; i++) {
			if (sum[a[i]] >= 3) {
				anss[i] = ans - sum[a[i]] * (sum[a[i]] - 1) / 2 + (sum[a[i]] - 1) * (sum[a[i]] - 2) / 2;
			} else if (sum[a[i]] == 2) {
				anss[i] = ans - sum[a[i]] * (sum[a[i]] - 1) / 2;
			} else {
				anss[i] = ans;
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.println(anss[i]);
		}
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 55996
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




















 
int main(){
    int n;
    scanf("%d", &n);
    double r1 = -INF, r2 = -INF, r3 = -INF;
    double l1 = INF, l2 = INF, l3 = INF;
    double u1 = -INF, u2 = -INF, u3 = -INF;
    double d1 = INF, d2 = INF, d3 = INF;
    for(int i = 0; i < n; i++){
        double x, y;
        char d;
        scanf("%lf %lf %c", &x, &y, &d);
        if(d == 'R'){
            r1 = max(r1, x);
            l3 = min(l3, x);
            u2 = max(u2, y);
            d2 = min(d2, y);
        }
        if(d == 'L'){
            r3 = max(r3, x);
            l1 = min(l1, x);
            u2 = max(u2, y);
            d2 = min(d2, y);
        }
        if(d == 'U'){
            r2 = max(r2, x);
            l2 = min(l2, x);
            u1 = max(u1, y);
            d3 = min(d3, y);
        }
        if(d == 'D'){
            r2 = max(r2, x);
            l2 = min(l2, x);
            u3 = max(u3, y);
            d1 = min(d1, y);
        }
    }
    double ans = 1e18;
    for(double i = 0; i <= 2e8; i += 0.5){
        ans = min(ans, (max({r1 + i, r2, r3 - i}) - min({l1 - i, l2, l3 + i})) * 
                       (max({u1 + i, u2, u3 - i}) - min({d1 - i, d2, d3 + i})));
    }
    printf("%.11lf\n", ans);
}

Measured memory_bytes: 384
/*****include*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/
void Exchange(int *a,int *b){
	int w;
	w = *a;
	*a = *b;
	*b = w;
}
/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	int *goal;
	int w;
	int n;
	int a,b;
	cin >> w >> n;
	goal = new int [w+1];
	for(int i=1;i<=w;i++){
		goal[i] = i;
		//cout << goal[i] << " ";
	}
	//cout << endl;
	for(int i=0;i<n;i++){
		scanf("%d,%d",&a,&b);
		Exchange(&goal[a],&goal[b]);
		//cout << goal[a] << " " << goal[b] << endl;
	}
	for(int i=1;i<=w;i++){
		cout << goal[i] << endl;
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

Measured memory_bytes: 1240
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    minimum = min(a_lst)
    maximum = max(a_lst)

    cost = 10 ** 9
    for i in range(maximum - minimum + 1):
        tmp_cost = 0
        std = minimum + i
        for j in range(n):
            a = a_lst[j]
            tmp_cost += (a - std) ** 2
        cost = min(tmp_cost, cost)

    print(cost)


if __name__ == '__main__':
    main()

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

int main(){
	long sum = 0;
	long fra[10000];
	int n;
	
	//上限'n'の入力
	cin >> n;
	
	//配列fra[]に値を代入、合計値sumに加算
	for(int i = 0; i < n; i++){
		cin >> fra[i];
		sum = sum + fra[i];
	}
	
	while(1){
		int flag = 0;
	//ソート本体
		for(int i = 0; i < n; i++){
			if(fra[i-1] > fra[i] && i > 0 && i < n){
				swap(fra[i-1],fra[i]);
			}
		}
	//ソート判定
		int count = 0;
		for(int i = 0; i < n; i++){
			if(fra[i-1] <= fra[i] && i > 0 ){
				count++;
			} 
			if(count == n-1){
				flag = 1;
			}
		}
		
		if(flag == 1)break;
	}
	
	cout << fra[0] << " " << fra[n-1] << " " << sum << endl;
	
	return 0;
}

Measured memory_bytes: 1240
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();
		int C = stdIn.nextInt();

		if(A == C && A != B){
			System.out.println("Yes");
		}
		else if(A == B && A != C){
			System.out.println("Yes");
		}
		else if(B == C && B != A){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
		stdIn.close();
	}
}


Measured memory_bytes: 35724
N = int(input())
A = list(map(int, input().split()))

from fractions import gcd
from functools import reduce

ans = reduce(gcd, A[1:]) # 0 番目を除いた　
ans = max(ans, reduce(gcd, A[:-1]))
stock = [A[0]] * N
revS  = [A[-1]] * N
for i in range(1, N):
    stock[i] = gcd(stock[i-1], A[i])

for i in range(N-2, -1, -1):
    revS[i] = gcd(revS[i+1], A[i] )

for i in range(1, N-1):
    # i はカウントしない
    ans = max( ans,  gcd(stock[i-1], revS[i+1]))
print(ans)

Measured memory_bytes: 87016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // ここにプログラムを追記
  int N;
  cin >> N;
  bool S = false;
  for(int i = 1; i <= N; i++){
    string c;
    cin >> c;
    if(c == "Y"){
      S = true;
      break;
    }
  }
  if(S){
    cout << "Four" <<endl;
  }
  else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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() {
    int n,m;
    cin >> n >> m;
    vector<int>a(n),b(n);
    vector<int>c(m),d(m);
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,m) cin >> c[i] >> d[i];
    vector<int>dist(n);
    rep(i,n) {
        int tmp = 1e9;
        rep(j,m) {
            tmp = min(tmp,abs(a[i]-c[j])+abs(b[i]-d[j]));
        }
        dist[i] = tmp;
    }
    rep(i,n) {
        int tmp = 1e9;
        rep(j,m) {
            tmp = min(tmp,abs(a[i]-c[j])+abs(b[i]-d[j]));
            if(dist[i] == tmp) {
                cout << j+1 << endl;
                break;
            }                
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long
int main () {
  ll N, Y;
  cin >> N >> Y;
  for (ll i = 0; i <= N; i++) {
    for (ll j = 0; j <= N; j++) {
      if (i + j > N) {
        // no  
      }  
      else {
        ll l = N - i - j;
        if (i * 10000 + j * 5000 + l * 1000 == Y) {
          cout << i << " " << j << " " << l << endl;
          return 0;  
        }  
      }
    }  
  }
  cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll pow_mod(ll x, ll y, ll mod)
{
	if (y == 0)
		return 1;

	if (y == 1)
		return x % mod;

	return (pow_mod(x, y - 1, mod) * x) % mod;
}

int X,Y,Z,K;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	cin>>X>>Y>>Z>>K;
	vector<ll> A(X),B(Y),C(Z);
	rep(i,0,X)cin>>A[i];
	rep(i,0,Y)cin>>B[i];
	rep(i,0,Z)cin>>C[i];
	sort(A.begin(),A.end(),greater<ll>());
	sort(B.begin(),B.end(),greater<ll>());
	vector<ll> temp,ans;
	rep(i,0,min(K,X)){
		rep(j,0,min(K,Y)){
			temp.push_back(A[i]+B[j]);
		}
	}
	sort(temp.begin(),temp.end(),greater<ll>());
	int limit = temp.size();
	rep(i,0,min(K,limit))rep(j,0,min(K,Z))ans.push_back(temp[i]+C[j]);
	sort(ans.begin(),ans.end(),greater<ll>());
	rep(i,0,K)cout<<ans[i]<<"\n";
	return 0;
}

Measured memory_bytes: 43388
#include<stdio.h>
#include<math.h>

typedef struct{
  double x;
  double y;
}Zahyou;

void kock(int,Zahyou,Zahyou);

int main()
{
  int n;
  Zahyou p1,p2;
  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;
  scanf("%d",&n);

  printf("%f %f\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);


  return 0;
}

void kock(int n,Zahyou p1,Zahyou p2){
  Zahyou s,t,u;
  
  s.x = (2*p1.x+p2.x)/3;
  s.y = (2*p1.y+p2.y)/3;
  t.x = (p1.x+2*p2.x)/3;
  t.y = (p1.y+2*p2.y)/3;
  u.x = (t.x-s.x)*cos(M_PI/3)-(t.y-s.y)*sin(M_PI/3)+s.x;
  u.y = (t.x-s.x)*sin(M_PI/3)+(t.y-s.y)*cos(M_PI/3)+s.y;
if( n == 0 ) return;
 kock(n-1,p1,s);
 printf("%f %f\n",s.x,s.y);
 kock(n-1,s,u);
 printf("%f %f\n",u.x,u.y);
 kock(n-1,u,t);
 printf("%f %f\n",t.x,t.y);
 kock(n-1,t,p2);
}

Measured memory_bytes: 636
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
int main()
{
	string str;
	getline(cin, str);
	istringstream iss(str);
	iss >> str;
	int H = stoi(str);
	iss >> str;
	int W = stoi(str);
	vector<vector<int>> v;
	v.resize(H);
	for (int i = 0; i < H; i++) {
		v[i].resize(W);
	}

	for (int h = 0; h < H; h++) {
		getline(cin, str);
		for (int w = 0; w < W; w++) {
			string item = str.substr(w, 1);
			if (item == ".") v[h][w] = 0;
			else v[h][w] = 1;
		}
	}

	do {
		int flag = 1;
		vector<int> erase_row;
		int hsize1 = v.size();
		for (int h = 0; h < hsize1; h++) {
			int row_flag = 1;
			int wsize1 = v[0].size();
			for (int w = 0; w < wsize1; w++) {
				if (v[h][w] == 1) {
					row_flag = 0;
					break;
				}
			}
			if (row_flag) {
				erase_row.push_back(h);
			}
		}
		for (int h = erase_row.size() - 1; h >= 0; h--) {
			v.erase(v.begin() + erase_row[h]);
		}
		vector<int> erase_col;
		int wsize2 = v[0].size();
		for (int w = 0; w < wsize2; w++) {
			int col_flag = 1;
			int hsize2 = v.size();
			for (int h = 0; h < hsize2; h++) {
				if (v[h][w] == 1) {
					col_flag = 0;
					break;
				}
			}
			if (col_flag) {
				erase_col.push_back(w);
			}
		}
		for (int i = erase_col.size() - 1; i >= 0; i--) {
			int hsize3 = v.size();
			for (int h = 0; h < hsize3; h++) {
				v[h].erase(v[h].begin() + erase_col[i]);
			}
		}
		if (erase_row.size() == 0 && erase_col.size() == 0) break;
	} while (1);
	int hsize4 = v.size();
	for (int h = 0; h < hsize4; h++) {
		int wsize4 = v[0].size();
		for (int w = 0; w < wsize4; w++) {
			if (v[h][w] == 0) cout << ".";
			else cout << "#";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256