akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;


bool dp[85][85][13000];

int main() {
  int H,W;
  cin >> H >> W;
  vector< vector< int > > A(82, vector<int>(82,0));
  vector< vector< int > > A1(82, vector<int>(82,0));
  vector< vector< int > > A2(82, vector<int>(82,0));
  vector< vector< int > > B(82, vector<int>(82,0));
  for (int y=1; y<H+1; ++y ) 
    for (int x=1; x<W+1; ++x ) 
      cin >> A[x][y];
  for (int y=1; y<H+1; ++y ) 
    for (int x=1; x<W+1; ++x ) 
      cin >> B[x][y];
  for (int y=1; y<H+1; ++y ) 
    for (int x=1; x<W+1; ++x ) {
      A1[x][y] = A[x][y] - B[x][y] + 80;
      A2[x][y] = B[x][y] - A[x][y] + 80;
    }

  dp[0][1][0] = true;
  for (int y=1; y<H+1; ++y ) 
    for (int x=1; x<W+1; ++x ) 
      for (int num=0; num<13000; ++num ) {
        if ( num - A1[x][y] >= 0 ) 
          dp[x][y][num] |= dp[x-1][y][num-A1[x][y]] | dp[x][y-1][num-A1[x][y]];
        if ( num - A2[x][y] >= 0 ) 
          dp[x][y][num] |= dp[x-1][y][num-A2[x][y]] | dp[x][y-1][num-A2[x][y]];
      }

  int num;
  for (num=0; num<13000/2; ++num ) {
    if ( dp[W][H][ 80*(H+W-1) + num ] ) break;
    if ( dp[W][H][ 80*(H+W-1) - num ] ) break;
  }
  cout << num << endl;

//  for (int y=1; y<H+1; ++y ) 
//    for (int x=1; x<W+1; ++x ) {
//      cout << "--- " << x << ", " << y << endl << " ";
//      for ( num=0; num<13000; ++num )
//        if ( dp[x][y][num] ) cout << num << " ";
//      cout << endl;
//    }

  return 0;
}


Measured memory_bytes: 87296
/*
 * ===================================================================
 *
 *       Filename:  atb.cpp
 *
 *           Link:  
 *
 *        Created:  2019/04/20 20时03分25秒
 *
 *         Author:  duny31030 , duny31030@126.com
 *   Organization:  duny31030.top
 *
 * ===================================================================
 */
#include <bits/stdc++.h>
using namespace std;
#define clr(a, x) memset(a, x, sizeof(a))
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define pre(i,a,n) for(int i=n;i>=a;i--)
#define ll long long
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n,k;
char a[20];

int main()
{
	cin >> n;
	cin >> a;
	cin >> k;
	char tmp = a[k-1];
    for(int i = 0;i < n;i++)
	{
		if(a[i] != tmp)
		{
			cout << "*";
		}
		else 
		{
			cout << a[i];
		}
	}

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, string t) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << t << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T & a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T & a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<class T> void getVector(vector<T> & v) {
	for (int i = 0; i < v.size(); ++i)
		cin >> v[i];
}

bool in(int w, int x, int r) {
	return x - r >= 0 && x + r <= w;
}

int main() {
	while (true) {
		makev(v, 2);
		sort(all(v));
		if (v.back() == 0)return 0;
		say(v);
	}
}


Measured memory_bytes: 3100
from itertools import permutations as perm
n, m, r = map(int, input().split())
rs = list(map(int, input().split()))
grid = [[float('inf')]*n for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    grid[a-1][b-1] = c
    grid[b-1][a-1] = c
for i in range(n):
    for j in range(n):
        if i == j:
            grid[i][j] = 0
for k in range(n):
    for i in range(n):
        for j in range(n):
            grid[i][j] = min(grid[i][j], grid[i][k] + grid[k][j])

perms = rs
res = float('inf')
for p in perm(perms):
    tmp = 0
    for i in range(1,r):
        tmp += grid[p[i]-1][p[i-1]-1]
    res = min(res,tmp)
print(res)

Measured memory_bytes: 71168
n = gets.to_i
s = gets.chomp.split("")
ans = 0

for i in 1..n-1 do
    s1 = s[0,i].uniq
    s2 = s[i,n-i].uniq
    ans1 = 0
    for j in 0..s1.length-1 do
        if s2.include?(s1[j])
            ans1 = ans1 + 1
        end
    end
    if ans1 >= ans
        ans = ans1
    end
end

puts ans

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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> H(N);
  for(int &i:H)
    cin>>i;
  sort(H.begin(),H.end());
  long long j=0;
  for(int i=0;i<N-K;i++)
    j+=H[i];
  cout<<j<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n;
		int ice;
		int[] a;
		
		while(true){
			n = scan.nextInt();
			if(n == 0)break;
			
			a = new int[10];
			for(int i = 0; i < n; i++){
				ice = scan.nextInt();
				a[ice]++;
			}
			for(int i = 0; i < 10; i++){
				if(a[i] > 0){
					for(int j = 0; j < a[i]; j++){
						System.out.print("*");
					}
				}else System.out.print("-");
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 64868
/*                              _______                                _________
        |\     |         /\         |      |        /\        |\     |    |
        | \    |        /  \        |      |       /  \       | \    |    |
        |  \   |       /    \       |\-----       /    \      |  \   |    |
        |   \  |      /======\      | \          /======\     |   \  |    |     ====|
        |    \ |     /        \     |  \        /        \    |    \ |    |         |
        |     \|    /          \    |   \      /          \   |     \|    |_________|
    */
    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pb push_back
    #define mk make_pair
    #define endl "\n"
    #define vi vector<ll>
    #define vb vector<bool>
    #define pii pair<ll,ll>
    #define ss second
    #define ff first
    #define vpii vector<pii>
    #define vvi vector<vi >
    #define vs vector<string>
    #define vvs vector<vs >
    #define all(x) x.begin(),x.end()
    #define mii map<int,int>
    #define rep(i,n) for(ll i=0;i<n;i++)
    #define per(i,n) for(ll i=n-1;i>=0;i--)
    #define rep1(i,n) for(ll i=1;i<=n;i++)
    #define per1(i,n) for(ll i=n;i>0;i--)
    #define repeat(i,start,n) for(ll i=start;i<n;i++)
    #define inp(arr,n) int arr[n];rep(i,n){ cin>>arr[i];}
    #define inp1(arr,n) ll arr[n+1];rep1(i,n){ cin>>arr[i];}
    #define print(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";}
    #define print1(a,n) for(ll i=1;i<=n;i++){ cout<<a[i]<<endl;}
    #define M 1000000007
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int t=1,T=1;
        //cin>>t;
        while(t--)
        {
            string s;
            cin>>s;
            int n=s.size();
            int n1=(n-1)/2;
            int n2=((n+3)/2)-1;
            rep(i,n/2)
            {
                if(s[i]!=s[n-i-1])
                {
                    cout<<"No";
                    return 0;
                }
            }
            rep(i,n1/2)
            {
                if(s[i]!=s[n1-i-1])
                {
                    cout<<"No";
                    return 0;
                }
            }
            for(int i=n2;i<n;i++)
            {
                if(s[i]!=s[n-i+n2-1])
                {
                    cout<<"No";
                    return 0;
                }
            }
            cout<<"Yes";
        }

    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
  ll ans = 0;
  int n;
  cin >> n;
  map<pair<int, int>, ll> mp;
  for(int i = 1; i <= n; i++){
    int a = i % 10;
    int b = i;
    while(b >= 10) b /= 10;
    if(a == 0 || b == 0) continue;
    pair<int, int> p = make_pair(a, b);
    if(mp.count(p)) mp.at(p)++;
    else mp[p] = 1;
  }
  for(pair<pair<int, int>, ll> x: mp){
    int a = x.first.first, b = x.first.second;
    pair<int, int> tmp = make_pair(b, a);
    if(mp.count(tmp)){
      ans += x.second * mp[tmp];
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,a,b,c=0,d=0;
  cin>>n>>a>>b;
  for(int i=a; i<=n; i++){
      c=i/10000+(i%10000)/1000+(i%1000)/100+(i%100)/10+(i%10);
      if(a<=c && c<=b){
          d=d+i;
      }
  }
  cout<<d<<endl;
       return 0;
}
   

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

int main(){
	int n,a[101],b[101];
	string s;

	while( cin >> n , n ){
		cin >> s;
		for(int i=0 ; i < n ; i++ ){
			cin >> a[i] >> b[i];
		}
		for(int i=n-1 ; i >= 0 ; i-- ){
			int d = abs( a[i] - b[i] );
			int i_ = a[i]-1;
			int j = b[i]-1;
			s[i_] = ((s[i_]-'a'+d)%26) + 'a';
			s[j] = ((s[j]-'a'+d)%26) + 'a';
			char t = s[i_];
			s[i_] = s[j];
			s[j] = t;
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;
#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<" " 
#define pr2(a,b)    cout<<a<<" "<<b<<" "
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()						
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void minize(ll& a,ll b){a=(a>b?b:a);};
inline void maxize(ll& a,ll b){a=(a<b?b:a);};
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll arr[MAXN+5];


ll Solves(){
	
	ll n,k,cnt=0,ans=0,x,r,c;			//1 2 3 4 5 6 7
	// PROCESSING IN HERE
	sc2(r,c);
	sc(n);
	fu(i,1,n)sc(arr[i]);
	
	vector<vi>res(r);
	fu(i,0,r-1){
		fu(j,0,c-1){
			if(!arr[n])n--;
			arr[n]--;
			res[i].pb(n);
		}
		if(i&1)reverse(all(res[i]));
	}
	
	fu(i,0,r-1){
		fu(j,0,c-1)pr(res[i][j]);
		cout<<endl;
	}
	re 0;
	// Hack it if you can :)
}

int main(){
//	INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	Solves();
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int q = in.nextInt();
        int[] a = new int[q];
        for (int i = 0; i < q; i++) {
            a[i] = in.nextInt() - 1;
        }

        long[] cand = new long[n];
        Arrays.fill(cand, k - q);
        for (int i = 0; i < q; i++) {
            cand[a[i]]++;
        }

        for (int i = 0; i < n; i++) {
            if (cand[i] > 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 59948
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int h[n];
	for(int i = 0 ; i < n  ; i++)cin >> h[i];

	int dp[n+1];
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i = 2; i <n ; i++)
	{
		dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1]<<"\n";
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
//#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
#define rep(i,a,n) for(Int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(Int (i)=(a); (i)<=(n); (i)++)
const int MAX_N = 1000000;
const Int MAX_N_Int = 1000000000000;

template <typename T>
void printV(const std::vector<T>& v, const char * const separator = " ")
{
    if(!v.empty())
    {
        std::copy(v.begin(),
                  --v.end(),
                  std::ostream_iterator<T>(std::cout, separator));
        std::cout << v.back() << "\n";
    }
}

int D;
string str,s,u;
vector<int>c(26);
vector<int>t(365);
vector<vector<int>> ss(365, vector<int>(26));
//vector<vector<int>> last(365, vector<int>(26));
vector<int> last(26);
int satisfaction=0;
int score(){
    for (int d = 0; d < D; ++d) {
        int i = t[d]-1;
        satisfaction+=ss[d][i];

        last[i]=d+1;
        for (int cc = 0; cc < 26; ++cc) {
            satisfaction-=c[cc]*((d+1)-last[cc]);
        }
        //printV(last);
        //cout<<i<<" "<<satisfaction<<endl;
        cout<<satisfaction<<endl;
    }

    return satisfaction;
}

int main() {
    IOS;
    prec;

    cin>>D;
    rep(i,0,26)cin>>c[i];
    for (int y = 0; y < D; ++y) {
        for (int x = 0; x < 26; ++x) {
            cin>>ss[y][x];
        }
    }
    rep(i,0,D)cin>>t[i];
    //cout<<score();
    score();









    cout<<endl;
    return 0;
}


Measured memory_bytes: 3700
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n,k,r,s,p;
    string t;
    cin>>n>>k>>r>>s>>p>>t;
    vvi dp(n+1,vi(2));
    dp[0][0]=0;
    dp[0][1]=0;
    rep(i,n){
        lli win;
        if(t[i]=='r') win=p;
        else if(t[i]=='s') win=r;
        else win=s;
        dp[i+1][1]=max(dp[i][1],dp[i][0]);
        if(i>=k&&t[i-k]==t[i]&&dp[i-k+1][0]==max(dp[i-k][0],dp[i-k][1])+win){
            dp[i+1][0]=max(dp[i][0],dp[i][1]);
        }
        else{
            dp[i+1][0]=max(dp[i][0],dp[i][1])+win;
        }

    }
    out(max(dp[n][0],dp[n][1]));
}   

Measured memory_bytes: 8960
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
  int n,m,k;cin>>n>>m>>k;

  vector<long long> a(n+1);
  vector<long long> b(m+1);

  for(int i=1;i<=n;++i) cin>>a[i],a[i]=a[i]+a[i-1];
  for(int i=1;i<=m;++i) cin>>b[i],b[i]=b[i]+b[i-1];
  
  long long sum=0,M;
  int j;

  M = max(prev(upper_bound(a.begin(),a.end(),k))-a.begin(),prev(upper_bound(b.begin(),b.end(),k))-b.begin());

  for(int i=1;i<=n;++i)
  { 
    if(a[i]>k) break;

    auto it = upper_bound(b.begin(),b.end(),k-a[i]);
    j = (it-b.begin())-1;
    sum=i+j;
    if(sum>M) M=sum;
  }
  cout<<M;
}


Measured memory_bytes: 6340
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    sc.close();
    int answer = 0;
    answer += (n * (n - 1)) / 2;
    answer += (m * (m - 1)) / 2;
    System.out.println(answer);
  }
}

Measured memory_bytes: 35584
#include <iostream>
#include <bitset>
#include <vector>

using namespace std;

int n;
int a, b;

vector<bitset<18>> Find(bitset<18> a, bitset<18> b, int n) {
    if (n == 1) {
        vector<bitset<18>> ans;
        ans.push_back(a);
        ans.push_back(b);
        return ans;
    }

    int x = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) {
            x = i;
            break;
        }
    }

    bitset<18> ap;
    bitset<18> bp;
    for (int i = 0; i < x; i++) {
        if (a[i]) {
            ap[i] = 1;
            bp[i] = 1;
        }
    }

    for (int i = x + 1; i < n; i++) {
        if (a[i]) {
            ap[i - 1] = 1;
        }
        if (b[i]) {
            bp[i - 1] = 1;
        }
    }

    bitset<18> cp = ap;
    cp[0] = cp[0] ^ 1;
    vector<bitset<18>> first = Find(ap, cp, n - 1);
    vector<bitset<18>> second = Find(cp, bp, n - 1);

    vector<bitset<18>> ans;
    for (int i = 0; i < first.size(); i++) {
        for (int j = n - 1; j > x; j--) {
            first[i][j] = first[i][j - 1];
        }
        first[i][x] = a[x];
    }

    for (int i = 0; i < second.size(); i++) {
        for (int j = n - 1; j > x; j--) {
            second[i][j] = second[i][j - 1];
        }
        second[i][x] = b[x];
    }

    for (int i = 0; i < first.size(); i++) ans.push_back(first[i]);
    for (int i = 0; i < second.size(); i++) ans.push_back(second[i]);

    return ans;
}

int main() {

    cin >> n >> a >> b;

    int tmp = a;
    int cnt_a, cnt_b;

    while (tmp) {
        if (tmp & 1) cnt_a++;
        tmp >>= 1;
    }

    tmp = b;
    while (tmp) {
        if (tmp & 1) cnt_b++;
        tmp >>= 1;
    }

    if ((cnt_a % 2) == (cnt_b % 2)) {
        cout << "NO";
        return 0;
    }

    cout << "YES" << endl;
    bitset<18> as(a);
    bitset<18> bs(b);

    vector<bitset<18>> res = Find(as, bs, n);
    for (int i = 0; i < res.size(); i++) {
        int num = 0;
        for (int j = 0; j < 18; j++) {
            if (res[i][j]) {
                num |= 1 << j;
            }
        }
        cout << num << ' ';
    }
}

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j, k) for (int i = j; i < k; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 60);

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

    double R;
    cin >> R;
    cout << R * 2 * M_PI << endl;

    return 0;
}


Measured memory_bytes: 3780
n = int(input())
AB = list(list(map(int,input().split())) for _ in range(n))
CD = list(list(map(int,input().split())) for _ in range(n))

CD.sort() # sort x in ascending order
AB.sort(key=lambda z: z[1], reverse=True) # sort x in descending order

dim_b = [[] for _ in range(n)]
for b in range(n):
    for r in range(n):
        if AB[r][0] < CD[b][0] and AB[r][1] < CD[b][1]:
            dim_b[b] += [r]

vis_r = [False]*(n)
for b in range(n): # ascending order of x
    for r in dim_b[b]: # descending order of y
        if not vis_r[r]: vis_r[r] = True; break

print(sum(vis_r))


Measured memory_bytes: 3064
sx,sy,tx,ty=map(int,input().split())
ans=('R'*(tx-sx)+'U'*(ty-sy)+'L'*(tx-sx)+'D'*(ty-sy+1)+
     'R'*(tx-sx+1)+'U'*(ty-sy+1)+'L'+'U'+'L'*(tx-sx+1)+
     'D'*(ty-sy+1)+'R')
print(ans)

Measured memory_bytes: 3060
def alchemist(n,v):
    _v = sorted(v)
    tmp = _v[0]

    for i in range(1,n):
        tmp = (tmp + _v[i])/2

    return tmp
if __name__ == '__main__':
    n = int(raw_input())
    v = map(float,raw_input().split())

    print alchemist(n,v)

Measured memory_bytes: 2568
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef long long ll;

int asc(const void* a, const void* b) {return *(int*)a - *(int*)b; }

int main() {
	ll l, r, d;
	scanf("%lld%lld%lld", &l, &r, &d);
	printf("%lld", r / d - (l-1) / d);

	return 0;
}

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

void call(int n) {
  int i = 1;
  do {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      do {
        if ( x % 10 == 3 ){
          cout << " " << i;
          break;
        }
        x /= 10;
      } while (x);
    }
  } while (++i <= n);
  cout << endl;
}

int main(){
  int n;
  cin >> n;
  call(n);
}



Measured memory_bytes: 3084
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    HashMap<Integer, Integer> map1 = new HashMap<Integer, Integer>();
    int[] c = new int[n];
    HashMap<Integer, Integer> map2 = new HashMap<Integer, Integer>();
    for(int i = 0; i < n; i++) {
      int b = sc.nextInt();
      a[i] = sc.nextInt();
      map1.put(a[i], b);
    }
    for(int i = 0; i < n; i++) {
      c[i] = sc.nextInt();
      int d = sc.nextInt();
      map2.put(c[i], d);
    }
    Arrays.sort(a);
    Arrays.sort(c);
    int[] used = new int[n];
    int ans = 0;
    for(int i = 0; i < n; i++) {
      for(int j = n - 1; j >= 0; j--) {
        if((c[i] > map1.get(a[j])) && (map2.get(c[i]) > a[j]) && (used[j] == 0)) {
          ans++;
          used[j] = 1;
          break;
        }
      }
    }
    System.out.println(ans);
  }
}

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

using namespace std;

typedef unsigned long long ull;

ull str2ull(string S)
{
    ull num = 0, k = 1;
    for (int i = S.size() - 1; i > -1; --i)
    {
        num += k * (S[i] - '0');
        k *= 10;
    }
    return num;
}

int main()
{
    string S;
    cin >> S;
    // 挟むか挟まないかの状態
    ull ans = 0, num;
    int pre;
    bool flag;
    for (int i = 0; i < (1 << (S.size()-1)); ++i)
    {
        flag = true;
        pre = 0;
        num = 0;
        for (int j = 0; j < S.size() - 1; ++j)
        {
            if ((i >> j) & 1)
            {
                num += str2ull(S.substr(pre, j + 1 - pre));
                pre = j+1;
            }
        }
        if (pre != -1)
            num += str2ull(S.substr(pre, S.size() - pre));
        else
            num += str2ull(S.substr(S.size() - 1, 1));
        
        ans += num;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
w = input()
dic_w = {}
for i in w:
    if i in dic_w:
        dic_w[i] += 1
    else:
        dic_w[i] = 1
flag = True
for i, v in dic_w.items():
    if v%2 != 0:
        flag = False
        break
print("Yes") if flag else print("No")

Measured memory_bytes: 3060
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }

int n;

pair<int, string> get(const string& s, const int mask)
{
    string pre;
    string suf;
    int cnt = 0;
    for(int i = 0; i < n; ++i)
        if ((1 << i) & mask)
        {
            pre.push_back(s[i]);
            ++cnt;
        }
        else
        {
            suf.push_back(s[i]);
        }
    reverse(suf.begin(), suf.end());
    return {cnt, pre + suf};
}

int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("output.txt", "w", stdout);
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);

    cin >> n;

    string s;
    cin >> s;

    int m = 1 << n;

    vector<pair<int, string> > have;
    have.reserve(m);

    string prefix = s.substr(0, n);
    for(int mask = 0; mask < m; ++mask)
        have.push_back(get(prefix, mask));

    long long result = 0;

    string suffix = s.substr(n, n);
    reverse(suffix.begin(), suffix.end());

    sort(begin(have), end(have));

    for(int mask = 0; mask < m; ++mask)
    {
        pair<int, string> cur = get(suffix, mask);

        auto l = lower_bound(begin(have), end(have), make_pair(cur.first, cur.second));
        auto r = upper_bound(begin(have), end(have), make_pair(cur.first, cur.second));
        result += distance(l,r);

//        cerr << cur.first << ' ' << cur.second << ' ' << distance(l,r) << ' ' << result << endl;
    }
    cout << result << endl;
}


Measured memory_bytes: 25216
a=list(input())[::-1]
b=list(input())[::-1]
c=list(input())[::-1]
if a==list("aca"):print("A");exit()
if a==list("abcb")[::-1]:print("C");exit()
turn="a"
while 1:
  if turn=="a":
    turn=a.pop()
    if len(a)==0:print("A");exit()
  elif turn=="b":
    turn=b.pop()
    if len(b)==0:print("B");exit()
  else:
    turn=c.pop()
    if len(c)==0:print("C");exit()

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int H[300],W[300],n,i,j,k;
  
  for(i=0;i<300;i++){
    scanf("%d%d",&H[i],&W[i]);
    if(H[i]==0&&W[i]==0) break;
  }
  n = i;

  for(i=0;i<n;i++){
    for(j=0;j<H[i];j++){
      for(k=0;k<W[i];k++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  
  return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#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()

const int MN = 210000;

// 1-indexed, [1, n]
template<class T>
class BIT {
	T bit[MN];
	int n;

public:
	BIT() {
		n = MN;
		memset(bit, 0, sizeof(bit));
	}

	T sum(int i) {
		++i;
		T s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}

	void add(int i, T x) {
		++i;
		while (i < n) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

int N;
int x[100010];
int y[100010];

bool ok(int t) {
	ll num = ((ll)(N + 1) * N / 2) / 2 + 1;

	BIT<int> T;

	const int B = 100010;

	int d = 0;
	T.add(d + B, 1);

	ll cnt = 0;

	rep(i, N) {
		if (x[i] <= t) {
			++d;
		} else {
			--d;
		}
		int r = T.sum(d + B - 1);
		cnt += r;
		T.add(d + B, 1);
	}
	return cnt >= num;
}

int main() {
	cin >> N;

	rep(i, N) {
		cin >> x[i];
		y[i] = x[i];
	}
	sort(y, y + N);

	int lo = 0, hi = N;
	if (ok(y[0])) hi = 0;

	while (hi - lo > 1) {
		int t = (lo + hi) / 2;
		if (ok(y[t])) {
			hi = t;
		} else {
			lo = t;
		}
	}

	cout << y[hi] << endl;

	return 0;
}

Measured memory_bytes: 1920
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String S = scan.nextLine();
        switch (S){
            case "ABC":
                System.out.println("ARC");
                break;
            case "ARC":
                System.out.println("ABC");
                break;
        }
    }
}

Measured memory_bytes: 27016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0046
{
    public class Program

    {
        public static void Main(string[] args)
        {
            List<double> mountains = new List<double>(50);
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) break;
                mountains.Add(double.Parse(line));
            }
            Console.WriteLine(mountains.Max() - mountains.Min());
        }
    }

}



Measured memory_bytes: 16276
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

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

int N,K,A[101010];

string solve(){
	rep(i,N) if(A[i]==K) return "POSSIBLE";
	int ma=A[N-1];
	if(ma<K) return "IMPOSSIBLE";

	int g=A[0];
	for(int i=1;i<N;i++) g=gcd(g,A[i]);

	if(K%g==0) return "POSSIBLE";
	else return "IMPOSSIBLE";
}

int main(){
	cin>>N>>K;
	rep(i,N){
		cin>>A[i];
	}
	sort(A,A+N);
	cout<<solve()<<endl;
	

}

Measured memory_bytes: 640
<?php  //?????§??? tamesi
while (true) {
    list($height, $width) = getInputExplodeBySpaces();
    
    if ($height == 0 && $width == 0) {
       break;
    }
    
    $chessBoardRectangle = new ChessBoardRectangle($height, $width);
    echo $chessBoardRectangle->makeChessBoardRectangle(), PHP_EOL;
}
 
function getInputExplodeBySpaces()
{
    return explode(' ', trim(fgets(STDIN)));
}
  
class Rectangle
{
    public $height;
    public $width;
    public $hashSymbol  = '#';
    
    public function __construct($height, $width)
    {
        $this->height = $height;
        $this->width  = $width;
    }

    public function setRectangleParts()
    {
        for ($i = 0; $i < $this->height; $i++) {
            for($j = 0; $j < $this->width; $j++) {
                $rectangleParts[$i][$j] = $this->hashSymbol;
            }
        }
        return $rectangleParts;
    }
    
    public function mergeRectangleParts($rectangleParts)
    {
        for ($i = 0; $i < $this->height; $i++) {
            $lines[] = implode($rectangleParts[$i]).PHP_EOL;
        }
        return implode($lines);
    }
}
 
class FrameRectangle extends Rectangle
{
    public $dotSymbol = '.';
    
    public function makeFrameRectangle()
    {
        $lines = $this->setRectangleParts();
        for ($i = 1; $i < $this->height - 1; $i++) {
            for($j = 1; $j < $this->width - 1; $j++) {
                $lines[$i][$j] = $this->dotSymbol; 
            }
        }
        
        return $this->mergeRectangleParts($lines);
    }
}

class ChessBoardRectangle extends FrameRectangle
{
    public function makeChessBoardRectangle()
    {
        $lines = $this->setRectangleParts();
        for ($i = 0; $i < $this->height; $i++) {
            for ($j = 0; $j < $this->width; $j++) {
                if ($j % 2 == 0 && $i % 2 ) {
                    $lines[$i][$j] = $this->dotSymbol;
                } elseif ($j % 2 && $i % 2 == 0) {
                    $lines[$i][$j] = $this->dotSymbol;
                }
            }
        }
        
        return $this->mergeRectangleParts($lines);
    }
}

Measured memory_bytes: 17780
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF=100000000000000LL;

int main() {
	int a,b;
	cin>>a>>b;
	if(a+b<10)cout<<a+b<<endl;
	else cout<<"error"<<endl;
	return 0;
}


Measured memory_bytes: 256
a,b,c=map(int,input().split())
if a==b==c:
    print(abs(a//2*b*c-(a-a//2)*b*c))
else:
    dv1= abs(a//2*b*c-(a-a//2)*b*c)
    dv2 =abs(b//2*a*c-(b-b//2)*a*c)
    dv3 =abs(c//2*b*a-(c-c//2)*b*a)
    print(min(dv1,dv2,dv3))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;

int main(void)
{
  int N;
  cin >> N;

  vector<int> b(N);
  vector<int> o;

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

  reverse(b.begin(), b.end());

  for (int i = 0; i < b.size(); i++) {
    if (b.size() - i == b[i]) {
      o.push_back(b[i]);
      b.erase(b.begin() + i);
      i = -1;
    }
  }

  reverse(o.begin(), o.end());

  if (b.empty()) {
    for (auto itr = o.begin(); itr != o.end(); ++itr) {
      cout << *itr << endl;
    }
  }
  else {
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k, res=INT_MAX;
    cin>>n>>k;
    int a[n];
    for(auto &x: a) cin>>x;
    for(int i=0; i<=n-k; ++i){
        int tmp=abs(a[i+k-1]-a[i]);
        res=min(res, tmp+min(abs(a[i]), abs(a[i+k-1])));
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 640
from decimal import Decimal
import math
a,b,c=input().split()

from decimal import Decimal
Decimal('2')**Decimal('0.5')
#Decimal('1.41421356237309504880168872421')

if(Decimal(c)**Decimal(0.5) -(Decimal(a)**Decimal('0.5')+ Decimal(b)**Decimal('0.5'))) >0 :
    print('Yes')
else:
    print('No')

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int arr[n],rev[n];
    for (int i=0;i<n;++i){
        cin>>arr[i];
        rev[i] = arr[i];
    }
    sort(rev,rev+n,greater<int>());
    int first = rev[0];
    for (int i=0;i<n;++i){
        if (arr[i]!=first){
            cout<<first;
        }
        else{
            cout<<rev[1];
        }
        cout<<"\n";
    }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ms(x, n) memset(x,n,sizeof(x));
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define rep1(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define PI acos(-1.0)
#define LONG_LONG_MAX 9223372036854775807
#define LONG_LONG_MIN -9223372036854775808
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

int n;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    vector<int> a(n+1);
    vector<int> vis(n+1);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    --a[1];
    bool flag = true;
    for (int i = 2; i <= n; ++i) {
        if (a[i] > a[i-1]) --a[i];
        else if (a[i] < a[i-1]) {
            flag = false;
            break;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

long int abs1(long int x){
    if (x > 0) return x;
    else return -x;
    
}

int main(){
    long int const INF = 10000000000000;
    long int h, w;
    cin >> h >> w;
    long int s = h * w;
    long int s1, s2;
    long int ans = INF;
    for (int i = 1; i < h; i++){
        long int sa = i * w;
        long int sb = ((h - i) / 2) * w;
        long int sc = ((h - i) / 2 + (h - i) % 2) * w;
        s1 = max(abs1(sa - sb), max(abs1(sb - sc), abs(sc - sa)));
        sb = (h - i) * (w / 2);
        sc = (h - i) * (w / 2 + w % 2);
        s2 = max(abs1(sa - sb), max(abs1(sb - sc), abs(sc - sa)));
        if (h == 2){
            s1 = INF;
        }
        
        ans = min(ans, min(s1, s2));
    }
    for (int i = 1; i < w; i++){
        long int sa = i * h;
        long int sb = ((w - i) / 2) * h;
        long int sc = ((w - i) / 2 + (w - i) % 2) * h;
        s1 = max(abs1(sa - sb), max(abs1(sb - sc), abs(sc - sa)));
        sb = (w - i) * (h / 2);
        sc = (w - i) * (h / 2 + h % 2);
        s2 = max(abs1(sa - sb), max(abs1(sb - sc), abs(sc - sa)));
        if (w == 2){
            s2 = INF;
        }
        ans = min(ans, min(s1, s2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    m, f, r = [int(i) for i in input().split()]
 
    if m == f == r == -1:
        break
 
    total = m + f
    if m == -1 or f == -1 or total < 30:
        print('F')
 
    elif total < 50 and r < 50:
        print('D')
 
    elif total < 65:
        print('C')
         
    elif total < 80:
        print('B')
         
    else:
        print('A')
        

Measured memory_bytes: 7648
using System;

namespace ALDS1_1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int n = int.Parse(str);

            int count = 1;
            str = Console.ReadLine();
            int x = int.Parse(str);
            int min = x;

            count += 1;
            str = Console.ReadLine();
            x = int.Parse(str);
            int profit = x - min;
            if(x<min)
            {
                min = x;
            }

            while(count < n)
            {
                str = Console.ReadLine();
                x = int.Parse(str);
                if (x - min > profit)
                {
                    profit = x - min;
                }
                if (x < min)
                {
                    min = x;
                }
                count += 1;
            }

            Console.WriteLine("{0}", profit);

        }
    }
}

Measured memory_bytes: 19972
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n;i++)
using namespace std;
int n;
vector<string>s(1001);
vector<int>edge[1001];
void dfs(int v,int rank){
    rep(i,rank)cout<<".";
    cout<<s[v]<<endl;
    for(int i=0;(long long)i<(long long)edge[v].size();i++)
        dfs(edge[v][i],rank+1);
    
}
int main(){
    cin>>n;
    rep(i,n){
        int vertex; cin>>vertex;
        string temp; cin>>temp;
        s[i]=temp;
        edge[vertex-1].push_back(i);
    }
    dfs(0,0);
}

Measured memory_bytes: 3344
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        k: usize,
    }
    let mut x = 0;
    let mut i = 0;
    let mut visited = HashSet::new();
    loop {
        i += 1;
        x = x * 10 + 7;
        if visited.contains(&x) {
            println!("-1");
            return;
        }
        visited.insert(x);
        x %= k;
        if x == 0 {
            break;
        }
    }
    println!("{}", i);
}


Measured memory_bytes: 29740
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int N, M, K, p[20][1010];
char s[15][1005];
inline int sum(int L1,int R1,int L2,int R2){
    return  p[L2][R2] + p[L1 - 1][R1 - 1] - p[L1 - 1][R2] - p[L2][R1 - 1] ;
}
inline void solve(){
	scanf("%d%d%d",&N,&M,&K);
	rep(i,0,N){
		scanf("%s",&s[i]);
		rep(j,0,M){
			if(s[i][j]=='1')p[i+1][j+1] = 1;
		}
	}
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i][j - 1]; }
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i - 1][j]; }
    int res = 1E9;
    VI cut;
	for(int bits = 0 ;bits<(1<<(N-1));bits++){
		if(__builtin_popcount(bits)>=res)continue;//剪枝 7ms ~ 3ms 
		cut.clear();
		for(int i=0;i<N-1;i++){
			if((bits>>i)&1){
				cut.pb(i+1);
			}
		}
		cut.pb(N);
		int  pcol = 1,ans=sz(cut)-1;
		int ok = 1;
		for(int i=1;i<=M;i++){
			int f=1,prow=1;
			for(int j=0;j<sz(cut);j++){
				if(sum(prow,pcol,cut[j],i)>K){
					f = 0;
					break;
				}
				prow = cut[j]+1;
			}
			if(!f){
				ans++;
				if(pcol==i){//Impossible
					ok = 0;
					break;
				}
				pcol = i;
			}
		}
		if(ok)res = min(res,ans);
	}
	printf("%d\n",res);
}
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    static Node nil = new Node(-1, null, null, null);
    static Node root = nil;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String order = sc.next();
            if (order.startsWith("i")) {
                    insert(new Node(sc.nextInt(), nil, nil, nil));
            } else {
                printInorder(root);
                System.out.println();
                printPreorder(root);
                System.out.println();
            }
        }
    }
    static void insert(Node z) {
        if (root.equals(nil)) {
            root = z;
            return;
        }
        
        Node p = root; // zの親
        while (true) {
            if (p.val > z.val) {
                if (p.left.equals(nil)) {
                    p.left = z;
                    break;
                } else {
                    p = p.left;
                }
            } else {
                if (p.right.equals(nil)) {
                    p.right = z;
                    break;
                } else {
                    p = p.right;
                }
            }
        }
    }
    
    // 螺旋本の擬似コードから
    static void insertOtehon(Node nd, Node z) {
        Node y = nil; // parent of x
        Node x = nd;
        while (!x.equals(nil)) {
            y = x; // 親を設定
            if (z.val < x.val) {
                x = x.left;
            } else {
                x = x.right;
            }
        }
        z.parent = y;
        
        //  Tが空の場合
        if (y.equals(nil))
            root = z;
        else if (z.val < y.val)
            y.left = z;
        else {
            y.right = z;
        }
    }
    
    static void printInorder(Node arg) {
        Node nd = arg;
        if(!nd.equals(nil)) {
            printInorder(nd.left);
            System.out.print(" " + nd.val);
            printInorder(nd.right);
        }
    }
    
    static void printPreorder(Node arg) {
        Node nd = arg;
        if(!nd.equals(nil)) {
            System.out.print(" " + nd.val);
            printPreorder(nd.left);
            printPreorder(nd.right);
        }
    }
    
    static class Node {
        int val;
        Node parent;
        Node left;
        Node right;
        
        Node (int val, Node parent, Node left, Node right) {
            this.val = val;
            this.parent = parent;
            this.left = left;
            this.right = right;
        }
        Node (int val) {
            this.val = val;
            this.parent = nil;
            this.left = nil;
            this.right = nil;
        }
    }
}



Measured memory_bytes: 215468
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

map<string,int> M;

int str2int(string S){
    if(M.find(S)==M.end()){
        int n = M.size();
        M[S]=n;
    }
    return M[S];
}

int E[200][200];//[a][b]=a to b

int main(){
    int N;
    while(cin>>N,N){
        fill(E[0],E[200],10000);
        M.clear();
        for(int i=0;i<N;i++){
            string S;
            cin>>S;
            for(int c=0;c<S.size();c++){
                if(S[c]=='-'){
                    string S1=S.substr(0,c);
                    string S2=S.substr(c+1,S.size()-c-1);
                    int i1=str2int(S1);
                    int i2=str2int(S2);
                    E[i1][i2]=1;
                    break;
                }
            }
        }
        int m = M.size();
        cout<<m<<endl;
        for(int i=0;i<m;i++){
            for(int j=0;j<m;j++){
                if(E[i][j]==1||E[j][i]==1) continue;
                //cond1
                bool b=false;
                for(int k=0;k<m;k++){
                    if(k==i||k==j) continue;
                    if((E[i][k]==1||E[k][i]==1)&&(E[j][k]==1||E[k][j]==1)){
                        b=true;
                        break;
                    }
                }
                //cond2,3
                for(int k=0;k<m;k++){
                    if(k==i||k==j) continue;
                    if((E[k][i]==1&&E[j][k]==1)||(E[i][k]==1&&E[k][j]==1)){
                        b=false;
                        break;
                    }
                }
                if(b) E[i][j]=E[j][i]=0;
            }
        }
        //WF
        for(int i=0;i<m;i++) E[i][i]=0;
        for(int k=0;k<m;k++){
            for(int i=0;i<m;i++){
                for(int j=0;j<m;j++){
                    E[i][j]=min(E[i][j],E[i][k]+E[k][j]);
                }
            }
        }
        int Q;
        cin>>Q;
        for(int i=0;i<Q;i++){
            string S;
            cin>>S;
            for(int c=0;c<S.size();c++){
                if(S[c]=='-'){
                    string S1=S.substr(0,c);
                    string S2=S.substr(c+1,S.size()-c-1);
                    int i1=str2int(S1);
                    int i2=str2int(S2);
                    if(i1>=m||i2>=m||E[i1][i2]%2==0){
                        cout<<"NO"<<endl;
                    }else{
                        cout<<"YES"<<endl;
                    }
                    break;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3240
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <string>
#include <iostream>

using namespace std;

int main(){
        int x1,y1,x2,y2,x3,y3,x4,y4;
        cin >> x1 >> y1 >> x2 >> y2;
        x3 = x2 + y1 - y2;
        y3 = y2 - x1 + x2;
        x4 = x3 + y2 - y3;
        y4 = y3 - x2 + x3;
        cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long

int main(){
	ll n,m,x[100000],y[100000];
	ll xsum =0ll, ysum = 0ll, sum = 0ll;

	scanf("%lld %lld",&n,&m);

	FOR(i,0,n) scanf("%lld",&x[i]);
	FOR(i,0,m) scanf("%lld",&y[i]);

	FOR(i,0,n){
		xsum += i*x[i] - (n-1-i)*x[i];
		xsum = xsum % (1000000000 + 7);		//オーバーフロー対策
	}
	FOR(i,0,m){
		ysum += i*y[i] - (m-1-i)*y[i];
		ysum = ysum % (1000000000 + 7);		//オーバーフロー対策
	}

	sum = xsum * ysum;

	printf("%lld\n",sum % (1000000000 + 7));
}

Measured memory_bytes: 1664