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

/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/


using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(ll i = 0; i<b; i++)
       res *= a;

    return res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	string x;
	cin >> x;
	ll k;
	cin >> k;
	ll len = x.length();
	//if k == 1pr 2 or ... and it 1111111....
	ll mini = min(len , k);
	loop(mini)
	{
		if(x[i] - '0' > 1)
		{
			cout << x[i] << endl;
			return 0;
		}
	}
	cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 256
//B - Around Square: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, aux1;
    double aux2;
    cin >> n;
    for(int i = n; i > 0; i--) {
        aux1 = sqrt(i);
        aux2 = sqrt(i);
        if(aux1 == aux2) {
            cout << i << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<long> v(87);//ここで多分セグフォしてる・・・
    v[0]=2;
    v[1]=1;

    for(int i=2;i<=n;i++){
        v[i]=v[i-1]+v[i-2];
    }
    cout<<v[n]<<endl;
}

    

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

const int MAX = 510000;

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

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

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

int main(){
    COMinit();
    ll N,K;
    cin>>N>>K;
    vector <ll> a(N);
    rep(i,0,N)cin>>a[i];
    sort(a.begin(),a.end());
    ll sum=0;

    rep(i,0,N){
        if(N-i-1>=0){
            if(N-i-1>=K-1){
                sum -= COM(N-i-1,K-1)*a[i]%MOD;
                sum += COM(N-i-1,K-1)*a[N-i-1]%MOD;
                sum %= MOD;
            }
        }
    }
    if(sum<0)sum+=MOD;
    cout<<sum;
    return 0;
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 1005

int H,W,K;
int table[SIZE][SIZE];
char base_map[SIZE][SIZE];


int main(){

	scanf("%d %d %d",&H,&W,&K);

	for(int row = 0; row < H; row++){

		scanf("%s",base_map[row]);
	}

	table[0][0] = -1;
	int North,West;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			if(row == 0 && col == 0)continue;

			North = -1,West = -1;

			if(row > 0){
				if(base_map[row-1][col] == '.' && table[row-1][col] <= 0){

					North = K;
				}else{

					North = table[row-1][col]-1;
				}
			}
			if(col > 0){
				if(base_map[row][col-1] == '.' && table[row][col-1] <= 0){

					West = K;

				}else{

					West = table[row][col-1]-1;
				}

			}
			table[row][col] = max(North,West);
		}
	}

	if(table[H-1][W-1] > 0){

		printf("Chieno\n");

	}else{

		printf("Cacao\n");
	}

	return 0;
}



Measured memory_bytes: 8056
# using dp with memoization, TLE
from sys import stdin
N, W = map(int, input().split())
m = stdin.read().splitlines()
s = [[int(i) for i in line.split()] for line in m]

dp = [0] * (W + 1)
next_dp = [0] * (W + 1)
for n in range(1, N + 1):
    for w in range(0, W + 1):
        if w >= s[n - 1][0]:
            next_dp[w] = max(next_dp[w], dp[w],
                             dp[w - s[n - 1][0]] + s[n - 1][1])
    dp = next_dp[:]
print(dp[W])


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

// Macros
#define PRAGMA(x) _Pragma(#x)
//
#define F  first
#define S  second
#define PB push_back
#define MP make_pair
//
#define ALL(container)   container.begin(),container.end()
#define MAKE_UNIQUE(vec) do { PRAGMA(message "DO NOT FORGET TO SORT THE VECTOR !!!"); vec.erase(unique(ALL(vec)),vec.end()); } while(0)
// vec.resize() sucks, use vec.assign()
// comparator -> return <

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = std::pair <int,int>;

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const set<T> &v)    { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const deque<T> &v)  { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T,S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T,S> &v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef LOCAL
	#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); d__f(_it, args); }
	void d__f(__attribute__((unused)) istream_iterator<string> it) {}
	template<typename Head, typename... Tail> void d__f(istream_iterator<string> it, Head H, Tail... T) { cerr << *it << " <=> [" << H << "]\n"; d__f(++it, T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

const ld PI = acosl(-1);

signed main() {
	std::ios::sync_with_stdio(false); //Warning: Do NOT use C I/O now.
	std::cin.tie(nullptr); //Note: Comment out this line for interactive questions.
	std::cout.setf(std::ios::fixed); std::cout.precision(20); //Note: To output decimals correctly.

	// int tt; cin >> tt;
	// for(int test_no = 1; test_no <= tt; ++test_no){}

	int a, b, h, m;
	cin >> a >> b >> h >> m;

	ld minute_angle = (m % 60) * (360/60);
	ld hour_angle = (h % 12) * (360/12) + (m % 60) * (((ld)360)/12/60);

	minute_angle *= PI/180;
	hour_angle *= PI/180;

	pair<ld,ld> p1 = {a * sin(minute_angle), a * cos(minute_angle)};
	pair<ld,ld> p2 = {b * sin(hour_angle), b * cos(hour_angle)};

	#define sq(x) (x)*(x)

	ld ans = sqrtl(sq(p1.F - p2.F) + sq(p1.S - p2.S));
	cout << ans << "\n";
}


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

int main(void)
{
    int K;
    cin >> K;
    string S;
    cin >> S;
    int i;

    int numS = S.size();
    if(numS<=K){
        cout << S << endl;
    }
    else{
        for(i=0;i<=K-1;i++){
            cout << S[i] ;
        }
         cout << "..." << endl;
    }

    

    return 0;
}

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

class Program
{

    static void Main(string[] args)
    {
        var S = Console.ReadLine();
        if (S.Length % 2 == 0)
        {
            Console.WriteLine(S);
        }
        else
        {
            var ans = new System.Text.StringBuilder();
            for (int i = S.Length - 1; i >= 0; i--)
            {
                ans.Append(S[i]);
            }

            Console.WriteLine(ans);
        }
    }
}



Measured memory_bytes: 13140
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto n = readln.chomp.to!int;
  writeln(n/3);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(N) for(int i=0;i<N;i++)
#define up cout<<"U"
#define down cout<<"D"
#define right cout<<"R"
#define left cout<<"L"

int main(){
  int sx, sy, tx, ty;
  cin>>sx>>sy>>tx>>ty;
  int x=tx-sx, y=ty-sy;
  
  string S="";
  
  rep(y)
    up;
  rep(x)
    right;
  rep(y)
    down;
  rep(x+1)
    left;
  rep(y+1)
    up;
  rep(x+1)
    right;
  down;
  right;
  rep(y+1)
    down;
  rep(x+1)
    left;
  up;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[])
{
  int A, B, K;
  scanf("%d", &K);
  scanf("%d %d", &A, &B);

  if (A % K == 0 || B % K == 0 || A / K != B / K)
  {
    printf("OK");
  }
  else
  {
    printf("NG");
  }

  return 0;
}

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

using namespace std;

using ll = long long int;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

bool check(string s, string t, int i) {
	bool res = true;

	int m = t.size();
	for (int j = 0; j < m; j++) {
		if (s[i + j] != '?' && s[i + j] != t[j]) {
			res = false;
			break;
		}
	}

	return res;
}

string solve(string s, string t) {
	bool gameover = true;
	int n = s.size(), m = t.size();
	for (int i = n - m; i >= 0; i--) {
		if (!check(s, t, i)) {
			continue;
		}

		s.replace(i, m, t);
		gameover = false;
		break;
	}

	if (gameover) {
		return "UNRESTORABLE";
	} else {
		replace(s.begin(), s.end(), '?', 'a');
		return s;
	}
}

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

	string s, t;
	cin >> s >> t;

	cout << solve(s, t) << endl;
	return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
  int n, a, b, c, d, e;
  cin >> n >> a >> b >> c >> d >> e;

  int m = min({a, b, c, d, e});
  int ans = (n+m-1)/m + 4;
  cout << ans << endl;

  return 0;
}


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

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll x; cin >> x;
	FOR(i,1,oo) {
		x -= i;
		if (x <= 0) {
			cout << i << endl;
			return 0;
		}
	}


}



Measured memory_bytes: 256
using static System.Math;
using System.Collections.Generic;
using System;

public class P
{
    public int xmax { get; set; }
    public int xmin { get; set; }
    public int ymax { get; set; }
    public int ymin { get; set; }
}

public class hello
{
    public static int h, w;
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var p = 0;
        while (p++ < n)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            h = int.Parse(line[0]);
            w = int.Parse(line[1]);
            var map = new int[h, w];
            var d = new Dictionary<char, int>();
            var dp = 0;
            for (int i = 0; i < h; i++)
            {
                var s = Console.ReadLine().Trim();
                for (int j = 0; j < w; j++)
                {
                    var ss = s[j];
                    if (ss != '.')
                    {
                        if (!d.ContainsKey(ss)) d[ss] = dp++;
                        map[i, j] = d[ss];
                    }
                    else map[i, j] = 9;
                }
            }
            var ps = getPs(map, dp);
            getAns(map, dp, ps);
        }
    }
    static bool check (int[,] map, P[] ps, int t)
    {
        for (int i = ps[t].xmin; i <= ps[t].xmax; i++)
            for (int j = ps[t].ymin; j <= ps[t].ymax; j++)
            {
                if (!(map[i, j] == t | map[i, j] == 8)) return false;
            }
        for (int i = ps[t].xmin; i <= ps[t].xmax; i++)
            for (int j = ps[t].ymin; j <= ps[t].ymax; j++)
                map[i, j] = 8;
        return true;

    }
    static void getAns (int[,] map, int dp, P[] ps )
    {
        var count = 0;
        while (true)
        {
            var change= false;
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    var t = map[i, j];
                    if (t <= 6)
                    {
                        if (check(map, ps, t)) { change = true; count++; }
                    }
                }
            }
            if (!change) break;
        }
        Console.WriteLine(count == dp? "SAFE": "SUSPICIOUS");
    }
    static P[] getPs(int[,] map, int dp)
    {
        var ps = new P[dp];
        for (int i = 0; i < dp; i++)
            ps[i] = new P { xmax = 0, ymax = 0, xmin = int.MaxValue, ymin = int.MaxValue };
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                var mp = map[i, j];
                if (mp <= 6)
                {
                    ps[mp].xmax = Max(ps[mp].xmax, i);
                    ps[mp].ymax = Max(ps[mp].ymax, j);
                    ps[mp].xmin = Min(ps[mp].xmin, i);
                    ps[mp].ymin = Min(ps[mp].ymin, j);
                }
            }
        }
        return ps;
    }
}



Measured memory_bytes: 20040
/*||>>>> Praveen Ojha <<<<>>>> 26 May 2019 <<<<>>>> 17:46:36 <<<<||*/
// #pragma GCC optimize("Ofast") //(Very Fast but Inaccurate)
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //(Small operations in many loops)
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf 1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

int32_t main(){__
  int n,m,x,y;
  cin>>n>>m;
  vi blb[m],p(m);
  for(int i=0;i<m;i++){
    cin>>x;
    for(int j=0;j<x;j++){
      cin>>y;
      blb[i].push_back(y-1);
    }
  }
  for(int i=0;i<m;i++){
    cin>>p[i];
  }
  int ans=0;
  for(int i=0;i<(1<<n);i++){
    vi tt;
    for(int j=0;j<n;j++){
      if(i&(1<<j))
        tt.push_back(1);
      else
        tt.push_back(0);
    }
    int glw=0;
    for(int j=0;j<m;j++){
      int cnt=0;
      for(int k=0;k<sz(blb[j]);k++){
        if(tt[blb[j][k]]==1)
          cnt++;
      }
      if((cnt&1)==p[j])
        glw++;
    }
    if(glw==m)
      ans++;
  }
  cout<<ans<<"\n";
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,a) for(int i=0;i<(a);i++)
#define MOD 1000000007

ll num[300000];

int main(){
  int N,K; cin>>N>>K;
  for(int i=K+1;i<=N;i++){
    for(int j=i;j<=N;j+=i){
      num[j+K]++;
      num[j+i]--;
    }
  }
  for(int i=1;i<=N;i++) num[i]+=num[i-1];
  int s=0;
  if(K==0) s=1;
  ll ans=0;
  for(int i=K;i<=N;i++){
    ans+=(N-i)+num[i]-s;
  }
  cout<<ans+s<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

double dtor(double deg) {       // x¨WA
  return deg*M_PI/180;
}
double dist(double x, double y) {
  return sqrt(x*x+y*y);
}

int main() {
  double a,b,c,d;
  while(cin>>a>>b>>c>>d,a!=-1||b!=-1||c!=-1||d!=-1) {
    double bb = dtor(90.0-a);
    double cc = dtor(90.0-c);
    double A = dtor(abs(d-b));
    double res = 6378.1*acos(cos(bb)*cos(cc)+sin(bb)*sin(cc)*cos(A));
    printf("%.0f\n", res);
  }
}

Measured memory_bytes: 0
n=int(input())
a=[int(input()) for i in range(n)]

if n%2==0:
    a=sorted(a)
    if n==2:
        print(a[1]-a[0])
        exit()
    else:
        ans=0
        for i in range(n):
            if i<n//2-1:
                ans-=a[i]*2
            elif i==n//2-1:
                ans-=a[i]
            elif i==n//2:
                ans+=a[i]
            else:
                ans+=a[i]*2
        print(ans)
else:
    a=sorted(a,reverse=True)
    ans=0
    tmp=0
    for i in range(n):
        if i<n//2-1:
            tmp+=a[i]*2
        elif i==n//2-1 or i==n//2:
            tmp+=a[i]
        else:
            tmp-=a[i]*2
    ans=tmp
    tmp=0
    for i in range(n):
        if i<n//2:
            tmp+=a[i]*2
        elif i==n//2 or i==n//2+1:
            tmp-=a[i]
        else:
            tmp-=a[i]*2
    ans=max(ans,tmp)
    print(ans)
            

Measured memory_bytes: 51800
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll N, K;
  cin >> N >> K;
  vll A(N);
  ll g;
  ll m;
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    if(i==0){
      g = A.at(i);
      m = A.at(i);
    }
    else{
      g = __gcd(g, A.at(i));
      m = max(m, A.at(i));
    }
  }
  if(K <= m && K % g == 0) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long


#if 0
const int MOD = ;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}

inline int inv(int x) {
    return lgput(x, MOD - 2);
}
#endif

#if 0
int fact[], invfact[];

inline void prec(int n) {
    fact[0] = 1;
    for(int i = 1; i <= n; i++) {
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
    invfact[n] = lgput(fact[n], MOD - 2);
    for(int i = n - 1; i >= 0; i--) {
        invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
    }
}

inline int comb(int n, int k) {
    if(n < k) return 0;
    return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}
#endif

using namespace std;

const int N = 100;

int mat[N + 1][N + 1];

vector <int> g[N + 1];
int l[N + 1], r[N + 1];
int vis[N + 1], now = 0;

bool dfs(int nod) {
    for(auto it : g[nod]) {
        if(r[it] == 0) {
            l[nod] = it;
            r[it] = nod;
            return 1;
        }
    }
    vis[nod] = now;
    for(auto it : g[nod]) {
        if(vis[r[it]] < now && dfs(r[it])) {
            l[nod] = it;
            r[it] = nod;
            return 1;
        }
    }
    return 0;
}

int main() {
#if 0
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i, j, n, m;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> m;
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= m; j++) {
            cin >> mat[i][j];
        }
    }

    auto get = [&](int x) {
        return (x + m - 1) / m;
    };

    for(int t = 1; t <= m; t++) {
        for(i = 1; i <= n; i++) {
            g[i].clear();
            l[i] = r[i] = 0;
            for(j = t; j <= m; j++) {
                g[i].push_back(get(mat[i][j]));
            }
        }
        bool flag = 1;
        while(flag) {
            now++, flag = 0;
            for(i = 1; i <= n; i++) {
                if(l[i] == 0)
                    flag |= dfs(i);
            }
        }
        for(i = 1; i <= n; i++) {
            j = t;
            while(j <= m && get(mat[i][j]) != l[i]) {
                j++;
            }
            swap(mat[i][j], mat[i][t]);
        }
    }

    for(i = 1; i <= n; i++) {
        for(j = 1; j <= m; j++) {
            cout << mat[i][j] << " ";
        }
        cout << "\n";
    }

    for(j = 1; j <= m; j++) {
        vector <int> cur;
        for(i = 1; i <= n; i++) {
            cur.push_back(mat[i][j]);
        }
        sort(cur.begin(), cur.end());
        for(i = 0; i < n; i++) {
            mat[i + 1][j] = cur[i];
        }
    }
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= m; j++) {
            cout << mat[i][j] << " ";
        }
        cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "YES" : "NO") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

//vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

int main()
{
    string a,b;
    cin >> a >> b;
    if(a == "H")
    {
        if(b == "H")
            cout << "H";
        else
            cout << "D";
    }
    else
    {
        if(b == "H")
            cout << "D";
        else
            cout << "H";
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int n,t,cnt[9];
int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		int x;
		scanf("%d",&x);
		if(x >= 3200)t++;else{
			cnt[x/400]++;
		}
	}
	int A = 0,B = 0;
	for(int i=0; i<8; i++)if(cnt[i])A++;
	printf("%d %d\n",A==0?1:A,A+t);
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I,m=0;
		List<int> li=new List<int>(n);
		for(int i = 0;i<n;i++) {
			int q=sc.I;
			m=Math.Max(m,q);
			if(i==0||li[li.Count-1]!=q){li.Add(q);}
		}
		m++;
		n=li.Count;
		int[] h=new int[m];
		int[] b=new int[m];
		int[] r1=new int[n];
		int k=0;
		for(int i = 0;i<n;i++) {
			h[li[i]]++;
			r1[i]=r1[i!=0?i-1:0];
			if(h[li[i]]>=2){
				k++;
				r1[i]=(r1[i]+1+r1[b[li[i]]])%mod;
			}
			b[li[i]]=i;
		}
		Console.WriteLine("{0}",(r1[n-1]+1)%mod);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> cards(N);
  rep(i, cards.size()) {
    cin >> cards.at(i);
  }
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  
  int Alice = 0, Bob = 0;
  rep(i, cards.size()) {
    if (i % 2 == 0) Alice += cards.at(i);
    else Bob += cards.at(i);
  }
  
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<algorithm>

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

using namespace std;

const double EPS=1e-9;

const int N_MAX=100;
bool Gauss_Jordan(int n,const double A[N_MAX][N_MAX],const double *b,double *x){
	static double B[N_MAX][N_MAX+1];
	rep(i,n){
		rep(j,n) B[i][j]=A[i][j];
		B[i][n]=b[i];
	}

	rep(i,n){
		int piv=i;
		for(int j=i;j<n;j++) if(abs(B[j][i])>abs(B[piv][i])) piv=j;
		rep(j,n+1) swap(B[i][j],B[piv][j]);

		if(abs(B[i][i])<EPS) return false;

		for(int j=i+1;j<=n;j++) B[i][j]/=B[i][i];
		rep(j,n) if(i!=j) for(int k=i+1;k<=n;k++) B[j][k]-=B[j][i]*B[i][k];
	}

	rep(i,n) x[i]=B[i][n];
	return true;
}

int main(){
	int s,n,k; scanf("%d%d%d",&s,&n,&k);
	s=abs(s);

	double p[101]={1};
	rep(i,k){
		double q[101]={};
		for(int j=1;j<=n;j++) rep(x,101-j) q[x+j]+=p[x]/n;
		copy(q,q+101,p);
	}

	static double A[N_MAX][N_MAX];
	double b[N_MAX],E_small[N_MAX];
	A[0][0]=1;
	for(int i=1;i<n*k;i++){
		A[i][i]=1;
		rep(j,n*k+1) A[i][abs(i-j)]-=p[j];
		b[i]=1;
	}
	Gauss_Jordan(n*k,A,b,E_small);

	if(s<n*k){
		printf("%.15f\n",E_small[s]);
		return 0;
	}

	static double P[101][101];
	rep(i,n*k) P[0][i]=p[i+1];
	P[0][n*k]=P[n*k][n*k]=1;
	rep(i,n*k-1) P[i+1][i]=1;

	double v[101];
	rep(i,n*k) v[i]=E_small[n*k-i-1];
	v[n*k]=1;

	rep(t,30){
		double v2[101]={};
		if((s-n*k+1)&(1<<t)){
			rep(i,n*k+1) rep(j,n*k+1) v2[i]+=P[i][j]*v[j];
			copy(v2,v2+n*k+1,v);
		}

		double P2[101][101]={};
		rep(i,n*k+1) rep(j,n*k+1) rep(l,n*k+1) P2[i][j]+=P[i][l]*P[l][j];
		rep(i,n*k+1) rep(j,n*k+1) P[i][j]=P2[i][j];
	}

	printf("%.15f\n",v[0]);

	return 0;
}

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

using namespace std;

vector<int> primes;

void init_primes() {
    for (int n=2; n<=200000; n++) {
        bool is_prime = true;
        for (vector<int>::iterator iter=primes.begin(); iter!=primes.end(); iter++) {
            if (n%(*iter) == 0) {
                is_prime = false;
                break;
            }
            if ((*iter)*(*iter) > n) {
                break;
            }
        }
        if (is_prime) {
            primes.push_back(n);
        }
    }
}

int m(int n, int p) {
    vector<int>::iterator base = lower_bound(primes.begin(), primes.end(), n+1);
    vector<int> sum_;
    for (int i=0; i<p; i++) {
        for (int j=i; i+j<p; j++) {
            sum_.push_back(*(base+i)+*(base+j));
        }
    }
    sort(sum_.begin(), sum_.end());
    return *(sum_.begin()+p-1);
}

int main() {
    int n, p;
    init_primes();
    while (true) {
        cin >> n >> p;
        if (n < 0) {
            break;
        }
        cout << m(n, p) << endl;
    }
    return 0;
}

Measured memory_bytes: 1348
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 10005 

const int INF = 1 << 30;
const int MOD = 1e9 + 7;

int V, E;
int dp[1 << 15][15];//dp[i][j]:=今まで訪れた頂点の情報がiで現在頂点jに入る時に出発点に戻る最小コスト
//0ならまだ訪れていない、1なら訪れた
int mp[15][15];//辺の重みの情報

void solve() {

	for (int i = 0; i < (1 << 15); i++)
	{
		for (int j = 0; j < 15; j++)
		{
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;

	for (int S = 0; S < (1 << V); S++)
	{
		for (int from = 0; from < V; from++)
		{
			if (dp[S][from] == INF)
			{
				continue;
			}
	
			for (int to = 0; to < V; to++)
			{
				//移動先
				if ((S >> to) & 1)
				{
					//既に訪れている
					continue;
				}
				if (mp[from][to] == INF)
				{
					continue;
				}
				//toに移動できる場合
				dp[S | (1 << to)][to] = min(dp[S | (1 << to)][to], dp[S][from] + mp[from][to]);
			}
		}
	}
}

int main() {

	cin >> V >> E;


	for (int i = 0; i < 15; i++)
	{
		for (int j = 0; j < 15; j++)
		{
			mp[i][j] = INF;
		}
	}

	//辺の情報を受け取る
	for (int i = 0; i < E; i++)
	{
		int s, t, d;
		cin >> s >> t >> d;//0-indexで入力が来る
		mp[s][t] = d;//s→tのコストがdである
	}

	solve();

	if (dp[(1 << V) - 1][0] == INF)
	{
		//経路が存在しなかった
		cout << "-1" << endl;
	}
	else
	{
		cout << dp[(1 << V) - 1][0] << endl;
	}

}


Measured memory_bytes: 5008
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
p = 10**9+7
N,K = map(int,input().split())
F = [1 for _ in range(N)]
for i in range(2,N):
    F[i] = (F[i-1]*i)%p
IF = [1 for _ in range(N)]
IF[N-1] = pow(F[N-1],p-2)
for i in range(N-2,1,-1):
    IF[i] = (IF[i+1]*(i+1))%p
A = sorted(list(map(int,input().split())))
A.insert(0,0)
cmax = 0
for j in range(K,N+1):
    cmax = (cmax+A[j]*F[j-1]*IF[K-1]*IF[j-K])%p
cmin = 0
for j in range(K-1,N):
    cmin = (cmin+A[N-j]*F[j]*IF[K-1]*IF[j-K+1])%p
print((cmax-cmin)%p)

Measured memory_bytes: 77488
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n, a, b; cin >> n >> a >> b;

  int ans = a * (n / (a + b));
  ans += min(a, (n % (a + b)));
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main(int argc, char const *argv[])
{
  int N, X=0, Y=0, sum = 0;
  cin >> N;
  vector<int> C(N);
  vector<int> V(N);
  vector<int> diff(N);
  for(int i=0;i < N;i++){
   cin >> V[i];
  }
  for(int i=0;i < N;i++){
   cin >> C[i];
  }
  for(int i=0; i<N; i++){
    if(V[i] - C[i] > 0){
      sum += V[i] - C[i];
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 510
#define pa pair<int,int>
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int n,ans[N*N],id[N*N],cnt[N],num=0;
pa a[N];
int main(){
//  freopen("a.in","r",stdin);
    n=read();for(int i=1;i<=n;++i){
        int x=read();id[x]=i;a[i]=make_pair(x,i);
    }sort(a+1,a+n+1);
    for(int i=1;i<=n;++i){
        int x=a[i].second,pos=a[i].first;ans[pos]=x;cnt[x]=n-x;
        for(int owo=1;owo<x;++owo){
            while(ans[++num]&&num<=pos) continue;
            if(num>pos){puts("No");return 0;}
            ans[num]=x;
        }
    }queue<int>q;
    for(int i=1;i<=n*n;++i){
        if(id[i]&&cnt[id[i]]) q.push(id[i]);
        if(ans[i]) continue;
        if(q.empty()){puts("No");return 0;}int x=q.front();
        ans[i]=x;if(--cnt[x]==0) q.pop();
    }puts("Yes");
    for(int i=1;i<=n*n;++i) printf("%d ",ans[i]);
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double pi = 3.14159265359;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------


string a, b;

int main()
{
	cin >> a >> b;
	string ans = "";
	int n = a.size() + b.size();
	int an = 0;
	int bn = 0;

	for (int i = 0;i < n;i++) {
		if (i % 2) {
			ans += b[bn];
			bn++;
		}
		else {
			ans += a[an];
			an++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <deque>
using namespace std;
int n, m;
int head[100010], to[200010], nxt[200010], cnt;
inline void addedge (int u, int v) { cnt++, to[cnt] = v, nxt[cnt] = head[u], head[u] = cnt; }
deque <int> q;
bool in[100010];
int main () {
	scanf ("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf ("%d%d", &u, &v);
		addedge (u, v);
		addedge (v, u);
	}
	q.push_back (1);
	in[1] = true;
	int u = 1, ans = 1;
	for (int e = head[u]; e; ) {
		int v = to[e];
		e = nxt[e];
		if (!in[v]) {
			q.push_front (v);
			in[v] = true, ans++, u = v;
			e = head[u];
		}
	}
	u = 1;
	for (int e = head[u]; e; ) {
		int v = to[e];
		e = nxt[e];
		if (!in[v]) {
			q.push_back (v);
			in[v] = true, ans++, u = v;
			e = head[u];
		}
	}
	printf ("%d\n", ans);
	while (!q.empty ()) printf ("%d ", q.front ()), q.pop_front ();
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

inline int read () {
    int ret = 0, t = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') t = -1, c = getchar();
    while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
    return ret * t;
}


int main () {
    string x, y;
    cin >> x >> y;
    int n = read(), m = read();
    string z; cin >> z;
    if (z == x) printf("%d %d\n", n - 1, m); else printf("%d %d\n", n, m - 1);
    return 0;
}

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


long long N;

int main() {
    cin >> N;

    int upper = sqrt(N);
    long long ans = N;
    for (int i = 1; i <= upper; i++) {
        if (N % i == 0) {
            long long rest = N / i;
            ans = min(ans, i + rest - 2);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10 ** 9 + 7

dp = [0] * (N + 1)
dp[0] = 1
for a in A:
    dp[a] = -1

for i in range(N):
    if dp[i] >= 0:
        if dp[i + 1] >= 0:
            dp[i + 1] += dp[i]
        if i + 2 <= N and dp[i + 2] >= 0:
            dp[i + 2] += dp[i]

print(dp[N] % mod)
# print(dp)


Measured memory_bytes: 468728
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define fi first
#define se second
#define db double
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define int LL
const int MAXN = 5e5 + 5;
const int MAX = 1e18;
int n,a[MAXN],mx[MAXN],ans[MAXN];

signed main(){
    scanf("%lld",&n);LL deg0 = 0;
    FOR(i,0,n) scanf("%lld",a+i);
    if(n == 0 && a[0]!= 1){
        puts("-1");
        return 0;
    }
    if(n != 0 && a[0] != 0){
        puts("-1");
        return 0;
    }
    mx[0] = 1;
    FOR(i,1,n){
        mx[i] = (mx[i-1]-a[i-1])*2;
        if(mx[i] < a[i]){
            puts("-1");
            return 0;
        }
        if(mx[i] <= 0){
            puts("-1");
            return 0;
        }
        mx[i] = std::min(mx[i],MAX);
    }
    int res = 0;
    ROF(i,n,0){
        ans[i] = a[i]+ans[i+1];
        ans[i] = std::min(ans[i],mx[i]);
        res += ans[i];
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 6112
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main(void)
{
  long N,D;
  cin >> N >> D;
  vector<long> x(N);
  vector<long> y(N);

  for(int i = 0;i < N; i++)
  {
    cin >> x[i] >> y[i];
  }
  
  long dist;
  int count = 0;
  for(int i = 0;i < N; i++)
  {
    long distx = x[i] * x[i];
    long disty = y[i] * y[i];

    dist = distx + disty; 
    
    if(dist <= D * D)
    {
      count++;
    }
  }
  
  cout << count;
  
 

}

Measured memory_bytes: 6040
N, M, K = map(int, input().split())  # N行, M列, K個黒くしたい

flag = False

for i in range(N+1):
    for j in range(M+1):
        if K == (i*M + j*(N-i) - i*j):
            flag = True

if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main()
{
    IOS;
    string s;
    cin>>s;
    int sum=0;
    for(auto i:s)
        sum+=i-'0';
    if(sum%9==0)
        print("Yes");
    else
        print("No");
}

Measured memory_bytes: 3744
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <string>
#include <queue>
using namespace std;

class Edge{
public:
	int to,rev;
	long long cap;
	Edge(int to,long long cap,int rev){
		this->to=to; this->cap=cap; this->rev=rev;
	}
};

const long long INF = 1L<<58;
int V;
vector<vector<Edge> > G;
vector<int> level,iter;

void addEdge(int from,int to,long long cap){
	G[from].push_back(Edge(to, cap, G[to].size()));
	G[to].push_back(Edge(from, 0, G[from].size()-1));
}

void D_bfs(int s){
	fill(begin(level), end(level), -1);
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty()){
		int v = que.front();	que.pop();
		for(const Edge &e:G[v]){
			if(e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v]+1;
				que.push(e.to);
			}
		}
	}
}

long long D_dfs(int v,int t,long long f){
	if(v==t)	return f;
	for(int &i=iter[v] ; i<G[v].size(); ++i){
		Edge &e = G[v][i];
		if(e.cap > 0 && level[v] < level[e.to]){
			long long d = D_dfs(e.to, t, min(f ,e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

long long Dinic(int s,int t){
	long long flow = 0;
	while(true){
		D_bfs(s);
		if(level[t] < 0)	return flow;
		fill(begin(iter), end(iter), 0);
		long long f=0;
		while( (f=D_dfs(s, t, INF)) > 0)	flow += f;
	}
}

int main(){
	int N;
	long long W;
	unordered_map<string, int> weeks;
	for(string s:{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"})	weeks.insert(make_pair(s, weeks.size()+1));
	while(true){
		cin>>N>>W;
		if(N==0)	break;

		V=10+N+1;
		level.resize(V,0);
		iter.resize(V,0);
		G.clear();
		G.resize(V,vector<Edge>());

		for(int i=1; i<=7; ++i)	addEdge(0,i,W);
		long long T,sum=0;
		int C;
		for(int i=0; i<N; ++i){
			cin>>T>>C;
			sum+=T;
			for(int j=0; j<C; ++j){
				string week;
				cin>>week;
				addEdge(weeks[week], 10+i, min(T,W));
			}
			addEdge(10+i, 10+N, T);
		}

		long long ret = Dinic(0,10+N);
		cout << (ret>=sum? "Yes": "No") << endl;

	}
	return 0;
}

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

int main(){
	int a,b;
	char c;
	scanf("%d%d",&a,&b);
	int i;
	int e=b;
	for(i=1;b;i*=10)b/=10;
	double d=sqrt(a*i+e);
	long long f=sqrt(a*i+e);
//	printf("%lf %d",d,i);

	if(d-f==0)printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vll           vector<ll> 
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

const int N=1e6+1;

// aaaaaaaaaaaaaaaa
void solve() {
  int n; cin>>n;
  vi a(n),f(N,0);
  rep(i,0,n)
    cin>>a[i],f[a[i]]++;
  vi tot(N,0);
  rep(i,1,N) if (f[i])
    for (int j=2*i;j<N;j+=i)
      tot[j]++;
  int ans=0;
  rep(i,0,n) 
    if (f[a[i]]==1&&!tot[a[i]])
      ans++;
  cout<<ans<<'\n';
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // int _; cin >> _; while(_--)
  solve();
	return 0;
}


Measured memory_bytes: 11900
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back


int MOD=1000000007;
int N,M;
char S[1000];
signed main(){
    scanf("%lld",&N);
    scanf("%s",S);
    if(N%2==1){
        printf("No\n");
        return 0;
    }
    rep(i,N/2){
        if(S[i]!=S[i+N/2]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}


Measured memory_bytes: 128
n, k = map(int, input().split())
s = input()
ans = 0
isOdd = False
for i in range(0, n-1):
    if s[i] == s[i+1]:
        ans += 1
    else:
        isOdd = not isOdd
        if isOdd and k > 0:
            ans += 2
            k -= 1

print(min(ans, n-1))

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

const int INF = 10000;
const int VMAX = 108;

int main() {
  int n;
  cin >> n;
  int G[VMAX][VMAX];
  for (int i = 0; i < VMAX; i++) {
    for (int j = 0; j < VMAX; j++) {
      G[i][j] = (i == j ? 0 : INF);
    }
  }

  for (int i = 0; i < n; i++) {
    int r, k;
    cin >> r >> k;
    while (k > 0) {
      int t;
      cin >> t;
      G[r][t] = 1;
      k--;
    }
  }

  for (int k = 0; k < VMAX; k++) {
    for (int i = 0; i < VMAX; i++) {
      for (int j = 0; j < VMAX; j++) {
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }

  int p;
  cin >> p;
  for (int i = 0; i < p; i++) {
    int s, d, v;
    cin >> s >> d >> v;
    if (G[s][d] + 1 > v) {
      cout << "NA" << endl;
    } else {
      cout << G[s][d] + 1 << endl;
    }
  }
 
  return 0;
}

Measured memory_bytes: 1208
def main(test_case,clear_case):
    if test_case <= clear_case:
      return "Yes"
    else:
      return "No"
    
if __name__ == "__main__":
    input_num = input()
    num1 = int(input_num.split()[0])
    num2 = int(input_num.split()[1])
    print(main(num1,num2))

Measured memory_bytes: 2940
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M,K=map(int,input().split())
tree=UnionFind(N)
not_friend_candidates=[]

for i in range(M):
  A,B=list(map(int,input().split()))
  A-=1
  B-=1
  tree.union(A,B)
  not_friend_candidates.append([A,B])

for j in range(K):
  C,D=list(map(int,input().split()))
  C-=1
  D-=1
  not_friend_candidates.append([C,D])


ans=[0]*N
for i,j in not_friend_candidates:
  if tree.same(i,j):
    ans[i]-=1
    ans[j]-=1
for i in range(N):
  ans[i]+=tree.size(i)-1
print(*ans)

Measured memory_bytes: 44796