akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
#include <iterator>
#include <complex>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};//URDL
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-12;

bool check(int city,int prev,int old,double limit_rad,
	   const vector<complex<double> >& cities){
  complex<double> src = cities[old];
  complex<double> dst = cities[city];

  src -= cities[prev];
  dst -= cities[prev];
  double computed_arg = abs(arg(src) - arg(dst));

  return (limit_rad >= M_PI - min(computed_arg,
				  abs(2.0*M_PI - computed_arg)) - EPS);
}
class State {
public:
  int carrots;
  int city;
  int prev;
  int old;
  double remaining_distance;
  State(int _ct,int _p,int _o,int _c,double _r) :
    city(_ct),prev(_p),old(_o), carrots(_c), remaining_distance(_r) {}

  State(int _ct,int _c,double _r,int _d) :
    city(_ct), carrots(_c), remaining_distance(_r) {
    prev = 20;
    old = 20;
  }

  bool operator <(const State& s) const{
    return remaining_distance < s.remaining_distance;
  }
};

double dp[5001][21][21]; //dp[carrot][prev][now] := remaining distance
bool isok[21][21][21]; //cur,prev,old
double city_distance[21][21];

int main(){
  int total_cities;
  while(~scanf("%d",&total_cities)){
    double r,theta;
    vector<complex<double> > cities;
    scanf("%lf %lf",&r,&theta);
    double limit_rad = theta * M_PI / 180.0;
    for(int city_idx = 0; city_idx < total_cities; city_idx++){
      int x,y;
      scanf("%d %d",&x,&y);
      cities.push_back(complex<double>(x,y));
    }

    memset(isok,true,sizeof(isok));
    for(int old = 0; old < total_cities; old++){
      for(int prev = 0; prev < total_cities; prev++){
	for(int cur = 0; cur < total_cities; cur++){
	  isok[cur][prev][old] = check(cur,prev,old,limit_rad,cities);
	  city_distance[cur][prev] = abs(cities[cur] - cities[prev]);
	}
      }
    }

    priority_queue<State> que;
    que.push(State(0,0,r,0));
    int max_carrots = 0;
    memset(dp,0,sizeof(dp));

    while(!que.empty()){
      State s = que.top();
      que.pop();

      if(dp[s.carrots][s.prev][s.city] >= s.remaining_distance - EPS) continue;
      dp[s.carrots][s.prev][s.city] = s.remaining_distance;
      max_carrots = max(s.carrots,max_carrots);

      int next_city,next_prev,next_old;
      for(int to=0;to<total_cities;to++){
	if(to == s.city) continue;

	next_city = to;
	next_prev = s.city;
	next_old = s.prev;
	if(!isok[next_city][next_prev][next_old]) continue;
	if(dp[s.carrots+1][s.city][to] >= s.remaining_distance - city_distance[next_city][next_prev] - EPS) continue;

	que.push(State(next_city,next_prev,next_old,
		       s.carrots+1,s.remaining_distance - city_distance[next_city][next_prev]));
      }
    }

    printf("%d\n",max_carrots);
  }
}

Measured memory_bytes: 19344
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main(){
  int d; cin >> d;

  switch (d){
    case 25:
    {
      cout << "Christmas" << endl;
      break;
    }
    case 24:
    {
      cout << "Christmas Eve" << endl;
      break;
    }
    case 23:
    {
      cout << "Christmas Eve Eve" << endl;
      break;
    }
    case 22:
    {
      cout << "Christmas Eve Eve Eve" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
kaku = 0
s = 0
N,K = map(int,input().split())
for i in range(1,N+1):
  b = 0
  a = i
  for j in range(1000000):
    if a >= K:
      break
    a *= 2
    b += 1
  s = (1/N)*(1/2)**b
  kaku += s
print(kaku)

Measured memory_bytes: 3060
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
if b<=c:
  if a+b>=c:
    print(0)
  else:
    print(c-b-a)
else:
  if a+c>=b:
    print(0)
  else:
    print(b-c-a)

Measured memory_bytes: 9132
s = input()

first = int(s[:2])
second = int(s[2:])

firstFlag = 0
secondFlag = 0

if first > 12 or first < 1:
	firstFlag = 1

if second > 12 or second < 1:
	secondFlag = 1

if firstFlag == 0:
	if secondFlag == 0:
		print("AMBIGUOUS")
	else:
		print("MMYY")
elif firstFlag == 1:
	if secondFlag == 0:
		print("YYMM")
	else:
		print("NA")

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[55],b[55],c[55];
int main()
{
    int i,j,k,k1,k2;
    scanf("%s%s",a,b);
    k1=strlen(a);
    k2=strlen(b);
    strcpy(c,a);
    for(i=0;i<k1;i++)
    {
        if(a[i]=='?')
        c[i]='a';
    }
    for(i=k1;i>0;i--)
    {
        for(j=i-k2,k=0;j>=0&&k<k2;j++,k++)
        {
            if(a[j]!=b[k])
            {
                if(a[j]=='?')
                {
                    c[j]=b[k];
                    continue;
                }
                else
                break;
            }
        }
        if(k==k2)
        {
            printf("%s\n",c);
            return 0;
        }
        for(j=i-k2,k=0;j>=0&&k<k2;j++,k++)
        {
            if(a[j]!=b[k])
            {
                if(a[j]=='?')
                {
                    c[j]='a';
                    continue;
                }
                else
                break;
            }
        }
    }
    printf("UNRESTORABLE\n");
    return 0;
}


Measured memory_bytes: 128
def main():
    k,n = tuple([int(t)for t in input().split()])
    a = [int(t)for t in input().split()]

    l = a[0]
    dist = []
    for a_i in a[1:]:
        dist.append(a_i-l)
        l = a_i
    dist.append(k-a[-1]+a[0])

    print(k-max(dist))

if __name__ == "__main__":
    main()

Measured memory_bytes: 26444
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> // Common file
    #include <ext/pb_ds/tree_policy.hpp>
    #include <functional> // for less

    using namespace std;
    #define md 1000000007
    #define itn int
    #define pb push_back
    #define mp make_pair
    // #define ull unsigned long long int
    #define ll long long 
    // #define int ll
    #define ppi pair<int, int>
    #define ppl pair<ll, ll>
    #define vi vector<int>
    #define all(x) x.begin(), x.end()
    #define ff first
    #define lb lower_bound
    #define ub upper_bound
    #define ss second
    #define inf 1e9
    #define enld '\n'
    #define cuot cout
    #define trace1(x) cerr << #x << ": " << x << endl
    #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
    #define trace3(x, y, z)                                                        \
      cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
           << z << endl
    #define trace4(a, b, c, d)                                                     \
      cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
           << c << " | " << #d << ": " << d << endl
    #define trace5(a, b, c, d, e)                                                  \
      cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
           << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
    #define trace6(a, b, c, d, e, f)                                               \
      cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
           << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
           << #f << ": " << f << endl
    #define trace(v)                                                               \
      for (auto it = v.begin(); it != v.end(); it++)                               \
        cerr << *it << " ";                                                        \
      cerr << endl;
    #define linf 1e18
    #define reset(x) memset(x, 0, sizeof(x))
    #define rep(i, a, b) for (int i = a; i < b; i++)

    using namespace __gnu_pbds;

    typedef tree<int, null_type, less<int>, rb_tree_tag,
                 tree_order_statistics_node_update>
        oset;

    void fastio() {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
    }
    
   
    void solve()
    {  
        string s;cin>>s;
        int n=s.size();
        int o=0,e=0;
        rep(i,0,n){
            if(s[i]-'0' != i%2)e++;
        }

        rep(i,0,n){
            if(s[i]-'0' == i%2)o++;
        }   
        cout<<min(o,e)<<endl;
    }


    signed main() {
      fastio();
      int t;
      t = 1;
      // cin >> t;
      for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": ";
        solve();
      }
      return 0;
    }


Measured memory_bytes: 512
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;

const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf

#define sf scanf

#define ALL(x) x.begin(),x.end()
#define pb push_back

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
int ext_gcd(int a, int b, int & x, int & y) {
    //for finding modular inverse
    //if its return 1 ,then a has a mod inverse x mod b.
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = ext_gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

int main()

{
    IOS;
    //freopen("input.txt", "r", stdin);
     //freopen("output.txt", "w", stdout);
     string s;
     cin>>s;
     map<int,int>mm;
     mm[0]++;
     int p=1;
     int t=0;
     ll ans=0;
     int n=sz(s);
     irep(i,n-1,0){
        t=(t+(s[i]-'0')*p)%2019;
        ans+=mm[t];
        mm[t]++;
        p=(p*10)%2019;
     }
     cout<<ans<<endl;

     return 0;

}
///Alhamdulillah


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;

int D;
vector<int> c(26);
vector<vector<int>> s;
vector<int> spa(26,0);//経過日数
vector<int> t;
vector<set<int>> schedule(26);//各コンテストが何日目に開催されるか
ll contest(int day,int x){//day日にコンテストxを開催した時の満足度の増加量 1-indexed
    ll now=s.at(day-1).at(x-1);
    rep(i,26){
        if(i==x-1){
            spa.at(i)=0;
            continue;
        }
        spa.at(i)++;
        now-=spa.at(i)*c.at(i);
    }
    return now;
}

int main() {
    cin>>D;
    rep(i,26)cin>>c.at(i);
    s.resize(D,vector<int>(26));
    rep(i,D)rep(j,26){cin>>s.at(i).at(j);}
    t.resize(D);

    rep(i,D)cin>>t.at(i);
    rep(i,26){
        schedule.at(i).insert(0);
    }
    rep(i,D){
        schedule.at(t.at(i)-1).insert(i+1);
    }
    rep(i,26){
        schedule.at(i).insert(D+1);
    }
    ll ans=0;
    rep(i,D){
        ans+=contest(i+1,t.at(i));
        //cout<<ans<<endl;問題A用
    }
    //改善前のansがもとまっている
    int M;
    cin>>M;
    rep(query,M){
        int d,q;
        cin>>d>>q;
        int x=t.at(d-1);
        t.at(d-1)=q;
        int bx,nx;
        auto p=lower_bound(schedule.at(x-1).begin(),schedule.at(x-1).end(),d);
        p--;
        bx=*p;
        p++;p++;
        nx=*p;
        schedule.at(x-1).erase(d);
        int bq,nq;
        auto itr=lower_bound(schedule.at(q-1).begin(),schedule.at(q-1).end(),d);
        nq=*itr;
        itr--;
        bq=*itr;
        schedule.at(q-1).insert(d);
        ans+=s.at(d-1).at(q-1)-s.at(d-1).at(x-1);
        ans+=(d-bq)*(nq-d)*c.at(q-1);
        ans-=(d-bx)*(nx-d)*c.at(x-1);
        cout<<ans<<endl;
    }
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

 int main(){
   int a, b;
   cin >> a >> b;
   int now = 0;
   int ans;
  for(int i = 1; i <= b - a; i++){ 
    now += i;
    if(b - a == i) ans = now - b;
  }

print(ans);
 }

Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  int a; readV(a);
  int b; readV(b);
  int c; readV(c);
  int x; readV(x);

  int r = 0;
  foreach (i; 0..a+1)
    foreach (j; 0..b+1)
      foreach (k; 0..c+1)
        if (i*500+j*100+k*50 == x) ++r;

  writeln(r);
}


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

int main(){

  int a=0;
  int b=0;
  
  cin>>a>>b;
  
  for(int i=0;i<(2*a-1);i++){

    cout<<b-a+1+i<<" ";
    
  }

}


Measured memory_bytes: 256
/** "Ever tried.
         Ever failed.
               No matter.
                   Try Again.
                        Fail again.
                             Fail better.**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define endl "\n"
#define oo 0x3f3f3f3f3f3f3f3fLL
#define pb push_back
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define setdp memset(dp,-1,sizeof(dp))
#define db(x) cout<<" LOOK "<<(#x)<<" = "<<x <<'\n'
#define NumofDigits(n)   ((long long)log10(n)+1)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=5e5+5;
const  double EPS = 1e-9;
const int MOD = 1e9+7;
/*
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll fastpow(ll b, ll p)
{if(!p)return 1;ll ret = fastpow(b, p >> 1);ret *= ret;if(p&1)ret*= b;return ret;}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};*/
inline void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
   /// File();
    int n;
    cin>>n;
    pair<int,int>arr[55]={};
    int sumv=0,sumc=0;
    for(int i=0;i<n;i++)
        cin>>arr[i].first;
    for(int i=0;i<n;i++)
        cin>>arr[i].second;
    int ans=0;
    for(int i=0;i<n;i++)
      if(arr[i].first > arr[i].second)
         ans+=(arr[i].first - arr[i].second);
    cout<<ans;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var nums = GetNumbersInt();
                if (nums[0] == 0 && nums[1] == 0)
                {
                    break;
                }

                var row1 = "#" + new string(Enumerable.Repeat('.', nums[1] - 2).ToArray()) + "#";
                var row2 = new string(Enumerable.Repeat('#', nums[1]).ToArray());

                for (int i = 0; i < nums[0]; i++)
                {
                    if (i == 0 || i == nums[0] - 1)
                    {
                        System.Console.WriteLine(row2);
                    }
                    else
                    {
                        System.Console.WriteLine(row1);
                    }
                }

                System.Console.WriteLine();
            }
        }

        //static StreamReader Console = new StreamReader("input.txt");

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static List<int> GetNumbersInt(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
        }

        static List<long> GetNumbersLong(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
        }

        static List<double> GetNumbersDouble(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToList();
        }

        static List<string> GetStrings()
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
        }
    }
}

Measured memory_bytes: 10012
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();
    let c: usize = iterator.next().unwrap().parse().unwrap();

    if a >= b + c {
        return "0".to_string();
    }

    return (c - (a - b)).to_string();
}


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

int main()
{
  ll n,k;cin>>n>>k;
  ll keep,ans=0;
  for(ll i=0;i<n;i++){
    cin>>keep;
    if(keep>=k)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		solve();
	}
	
	public static void solve() {
		for(int i = 1; i <= 9; i++){
			for (int j = 1; j <= 9; j++) {
				System.out.printf("%dx%d=%d\n", i, j, i * j);
			}
		}
	}
}

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

cnt = 0
for i in range(1, N+1):
    first = str(i)[0]
    last = str(i)[-1]
    if first == last:
        cnt += 1
    if last != '0':
        if len(str(N)) == 2:
            if int(last+first) <= N:
                cnt += 1
        if len(str(N)) >= 3:
            for j in range(len(str(N))-2):
                cnt += 10**j
            middle = str(N)[1:-1]
            if last < str(N)[0]:
                cnt += 10**(len(str(N))-2)
            elif last == str(N)[0]:
                if first > str(N)[-1]:
                    cnt += int(middle)
                else:
                    cnt += int(middle) + 1

print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#define REP(i,n) for(int i = 0; i < n; i++)
using namespace std;
int main(void){
    // Your code here!
    long long n, k;
    cin >> n >> k;
    
    long long result;
    if(k % 2 == 0){
        result = (n/k) * (n/k) * (n/k) + ((n + (k/2))/k) * ((n + (k/2))/k) * ((n + (k/2))/k);
    }else{
        result = (n/k) * (n/k) * (n/k);
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int connum(int l, int r)
{
int mul = 1;
while(mul <= r) mul *= 10;
return l * mul + r;
}

void add(int k, int sum, vector<int> &c, vector<int> &result)
{
if(k == 0) {
result.push_back(sum);
return;
}
for(int i = 0; i < c.size(); ++i) {
if(c[i] == 0)
continue;
int tmp = c[i];
c[i] = 0;
add(k - 1, connum(sum, tmp), c, result);
c[i] = tmp;
}
return;
}

int main()
{
while(true) {
int n, k;
vector<int> c;
vector<int> result;
scanf("%d%d", &n, &k);
if(n == 0)
break;
c.resize(n);
for(int i = 0; i < n; ++i) 
scanf("%d", &c[i]);
add(k, 0, c, result);
sort(result.begin(), result.end());
result.erase(unique(result.begin(), result.end()), result.end());
printf("%d\n", result.size());
}
return 0;
}

Measured memory_bytes: 1108
def solve():
    n = input()
    for i in range(2 ** 3):
        op = ['+', '+', '+']
        for j in range(3):
            if (i >> j) & 1:
                op[j] = '-'
        f = n[0] + op[0] + n[1] + op[1] + n[2] + op[2] + n[3]
        if eval(f) == 7:
            print(f+'=7')
            exit()





if __name__ == "__main__":
    solve()

Measured memory_bytes: 9136
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <math.h>
#include <string.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)
#define mod 1000000007


int N, T, A, H[1234];
double t[1234], diff = 9999;
int position;

signed main(){

	cin >> N >> T >> A;
	for (int i = 0; i < N; i++){
		cin >> H[i];
		t[i] = (double)T - 0.006 * H[i];
		if (fabs(t[i] - A) < diff){
			position = i + 1;
			diff = fabs(t[i] - A);
		}
	}

	cout << position << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int h = vs[0];
			int a = vs[1];
			int ans = h / a;
			if (h % a != 0) {
				ans++;
			}
			Console.WriteLine(ans);



			Console.Out.Flush();
		}
	}
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  vector<int> v;

  rep(i, n) {
    int num;
    cin >> num;
    v.push_back(num);
  }
  sort(v.begin(), v.end());

  int maxnum = v[v.size() - 1];
  bool dp[maxnum + 1];
  bool dp2[maxnum + 1];

  rep(i, maxnum + 1) {
    dp[i] = true;
    dp2[i] = false;
  }

  int cnt = 0;

  for (auto num : v) {
    int times = 2;
    if (dp2[num] == false) {
      dp2[num] = true;
    } else {
      dp[num] = false;
    }

    while (true) {
      int val = num * times;
      if (val > maxnum) break;
      dp[val] = false;
      times++;
    }
  }

  for (auto num : v) {
    if (dp[num] == true) {
      cnt++;
      dp[num] = false;
    }
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 6160
import sys
readline = sys.stdin.readline

H,W = map(int,readline().split())
C = [None] * 10
for i in range(10):
  C[i] = list(map(int,readline().split()))

for k in range(10):
  for i in range(10):
    for j in range(10):
      C[i][j] = min(C[i][j], C[i][k] + C[k][j])

from collections import defaultdict
wall = defaultdict(int)
for i in range(H):
  for w in list(map(int,readline().split())):
    wall[w] += 1
  
ans = 0
for key,value in wall.items():
  if key == -1:
    continue
  ans += value * C[key][1]
  
print(ans)

Measured memory_bytes: 9452
#include <stdio.h>

int main()
{
	int a, b, keta, sum;
	
	while (scanf("%d %d", &a, &b) != EOF){
		keta = 1;
		sum = a + b;
		
		while (sum > 9){
			sum /= 10;
			keta++;
		}
		
		printf("%d\n", keta);
	}
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int P, Q, R;

int main() {
	cin >> P >> Q >> R;
	cout << P + Q + R - max({ P,Q,R }) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
const int LLINF = 1001001001;
using ll = long long;

/**
 * @brief クラスカル法で最小全域木のコストを求める
 * 
 */

// 頂点a, bをつなぐコストcostの（無向）辺
struct Edge {
  int a, b, cost;

  // sortできるよう、コストの大小で順序定義
  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

int V, E;

// 素集合データ構造
struct UnionFind {
  // parent[i]：データiが属する木の親の番号。i == parent[i]のとき、データiは木の根ノードである
  vector<int> parent;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int v_num) : parent(v_num), sizes(v_num, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    for (int i = 0; i < v_num; ++i) parent[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == parent[x]) return x;
    return parent[x] = find(parent[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    parent[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

// https://www.youtube.com/watch?v=CYEPCBFIwrY が流れわかりやすい
int kruskal(vector<Edge>& es, int V) {
  // costが小さいやつから順になるようソートする
  sort(es.begin(), es.end());

  UnionFind uf(V);
  int min_cost = 0;

  for (int ei = 0; ei < es.size(); ++ei) {
    Edge& e = es[ei];
    if (!uf.same(e.a, e.b)) {
      // 辺を追加しても閉路ができないなら、その辺を採用する
      min_cost += e.cost;
      uf.unite(e.a, e.b);
    }
  }
  return min_cost;
}

int main() {
  int v_num, e_num;  // V: 頂点数 | E: 辺の数
  cin >> v_num >> e_num;

  vector<Edge> es(e_num);  // edge setの略

  /** 
   * 頂点は0スタートな入力を想定しているので、--でデクリメントしていない。
   * 
   * 辺を格納していく。閉路が存在してもok。
   * 1 3 10
   * 4 2 20
   * 1 5 15
   * のような頂点1、頂点2、コストをあらわす入力を想定している。
   * e_num: 辺の本数
  */
  for (int i = 0; i < e_num; ++i) {
    cin >> es[i].a >> es[i].b >> es[i].cost;
  }

  cout << kruskal(es, v_num) << endl;

  return 0;
}



Measured memory_bytes: 4156
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

template<class T>bool chmax(T &a, const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}

template<class T>bool chmin(T &a, const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	string s;
	cin>>s;
	string l,r;
	int n=s.size();
	for(int i=0;i<(n-1)/2;i++){
		l.push_back(s[i]);
	}
	for(int i=(n+3)/2-1;i<n;i++){
		r.push_back(s[i]);
	}
	for(int i=0;i<l.size();i++){
		if(l[i]!=l[l.size()-i-1]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	if(l!=r){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
a,b,c,x,y = gets.split.map(&:to_i);
ans = 0

if a + b >= c * 2
	if x <= y
		ans += x * c * 2
		if b <= c * 2
			ans += b * (y - x)
		else
			ans += c * 2 * (y - x)
		end
	else
		ans += y * c * 2
		if a <= c * 2
			ans += a * (x - y)
		else
			ans += c * 2 * (x - y)
		end
	end
else
	ans += a * x + b * y
end

puts ans

Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main(){
    
    string S,T;
    cin >> S >> T;
    for(int i=0; i<S.size(); ++i){
        if(S==T){
            cout << "Yes";
            return 0;
        }
        S = S.back() + S.substr(0,S.size()-1);
    }
    cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
	int n, a, vmin, vmax;
	long sum;

	cin >> n >> a;
	sum = vmin = vmax = a;

	for(int i = 1; i < n; i++){
		cin >> a;
		vmin = min(vmin, a);
		vmax = max(vmax, a);
		sum += a;
	}
	cout << vmin << " " << vmax << " " << sum << endl;

	return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h> 
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=100005;
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=9999999;
int cal(int x)
{
	int ret=0;
	for(int t=x;t;t/=10) ret+=t%10;
	return ret;
}
int main()
{
	n=read();
	for(int i=1;i<n;i++){
		int j=n-i;
		ans=min(ans,cal(i)+cal(j));
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
vector<int> F[200001];
int bel=0;
vector<int> belong[200001];
map<int,int> p;
bool visited[200001];
void dfs(int now,int c){
    int cn=0;
    if(!visited[now]){
        visited[now]=true;
        belong[c].push_back(now);
        p[now]=c;
        //keyは人、値は所属番号
        for(int j=0;j<F[now].size();j++){
            int child = F[now][j];
            if(!visited[child]){
                dfs(child,c);
                cn++;
            }
        }
        if(cn==0){
            bel++;
            //もう回り切った＝＞所属しているグループを変える
        }
    }
    
}
int main(){
   //グラフの連結成分の数
    int n,m;
    cin>>n>>m;
    int ans=0;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        F[a].push_back(b);
        F[b].push_back(a);
    }
    rep(i,n){
        visited[i]=false;
    }
    rep(i,n){
        dfs(i,bel);
    }
    //cout<<bel<<endl;
    rep(i,bel){
        ans = max(ans,int(belong[i].size()));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 41612
#include <algorithm>
#include <iostream>
#include <vector>
int main()
{
    int N, M, X, Y;
    std::cin >> N >> M >> X >> Y;
    std::vector<int> xs{};
    std::vector<int> ys{};
    for (int i = 0; i < N; i++) {
        int x;
        std::cin >> x;
        xs.emplace_back(x);
    }
    for (int i = 0; i < M; i++) {
        int y;
        std::cin >> y;
        ys.emplace_back(y);
    }
    std::sort(xs.begin(), xs.end());
    std::sort(ys.begin(), ys.end());
    if (X < Y and xs.at(xs.size() - 1) < ys.at(0) and xs.at(xs.size() - 1) < Y and X < ys.at(0)) {
        std::cout << "No War" << std::endl;
    } else {
        std::cout << "War" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
n=int(input())
list1=[]
def apl1(l1):
    list1.append(l1)
for i in range(n):
    apl1(str(sorted(list(input()))))
list1.sort()
str1=list1[0]
ans=0
num=0
def num_1(num1):
    return ((num1+1)*num1)//2
for i in range(1,n):
    if str1==list1[i]:
        num+=1
    else:
        ans+=num_1(num)
        str1=list1[i]
        num=0
if num>=1:
    ans+=num_1(num)
print(ans)


Measured memory_bytes: 21284
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
using namespace std;
int gcd(int a, int b) {
	int v0 = a, v1 = b, v2 = a % b;
	while (v2 != 0) {
		v0 = v1;
		v1 = v2;
		v2 = v0 % v1;
	};
	return v1;
}

int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
int main()
{
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++)
	{
		cin >> d.at(i);
	}
	int ans = 0;
	int ans1 = 0;
	for (int i = 0; i < n - 1; i++)
	{
		if (i == 0)
		{
			ans = gcd(d.at(i), d.at(i + 1));
		}
		else
		{
			ans = gcd(ans, d.at(i + 1));
			
		}
	}
	cout << ans << endl;


}

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

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;

ll H, N;
ll A[1010], B[1010];
ll dp[100010];
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> H >> N;
	rep(i, N)cin >> A[i] >> B[i];
	rep(i, 100010)dp[i] = INF;
	rep(i, N) {
		rep(j, A[i]) {
			dp[j] = min(dp[j], B[i]);
		}
		for (int j = A[i]; j <= H; j++) {
			dp[j] = min(dp[j], dp[j - A[i]] + B[i]);
		}
	}
	cout << dp[H - 1] << endl;
	return 0;
}

Measured memory_bytes: 4456
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
    int N,M,K;
    cin>>N>>M>>K;
    int flg=0;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=M;j++){
            if(i*M-j*(i-(N-i))==K)flg=1;
            //printf("[%d][%d][%d]\n",i,j,i*M-j*(i-(N-i)));
        }
    }
    if(flg)puts("Yes");
    else puts("No");
    return 0;
}


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

using namespace std;
using ll = long long;

vector<ll> odd, even;

ll po(ll a, int b)
{
    if (b == 1)
        return a;
    
    if (b & 1)
        return po(a, b - 1) * a;
    
    return po(a * a, b / 2);
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    even.push_back(0);
    ll x; cin >> x;

    ll a = 1;
    while (po(a, 5) <= 1e18)
    {
        ll in = po(a, 5);
        
        if (in & 1)
            odd.push_back(a);
        else
            even.push_back(a);
        ++a;
    }
    
    if (x & 1)
    {
        for (int i = 0; i < odd.size(); ++i)
        {
            for (int j = 0; j < even.size(); ++j)
            {
                if (po(odd[i], 5) + po(even[j], 5) == x)
                {
                    cout << odd[i] << " " << -even[j];
                    return 0;
                }
                
                if (po(odd[i], 5) - po(even[j], 5) == x)
                {
                    cout << odd[i] << " " << even[j];
                    return 0;
                }
                
                if (po(even[j], 5) - po(odd[i], 5) == x)
                {
                    cout << even[j] << " " << odd[i];
                    return 0;
                }
            }
        }
    }
    else
    {
        for (int i = 0; i < even.size(); ++i)
        {
            for (int j = 0; j < even.size(); ++j)
            {
                if (po(even[i], 5) + po(even[j], 5) == x)
                {
                    cout << even[i] << " " << -even[j];
                    return 0;
                }
                
                if (po(even[i], 5) - po(even[j], 5) == x)
                {
                    cout << even[i] << " " << even[j];
                    return 0;
                }
            }
        }
        
        for (int k = 0; k < odd.size(); ++k)
        {
            for (int s = 0; s < odd.size(); ++s)
            {
                if (po(odd[k], 5) + po(odd[s], 5) == x)
                {
                    cout << odd[k] << " " << -odd[s];
                    return 0;
                }
                
                if (po(odd[k], 5) - po(odd[s], 5) == x)
                {
                    cout << odd[k] << " " << odd[s];
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 3716
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#include<stack>
#include<set>
#define int long long
#define MAX 1000000000000000000LL
int inf=100000000000007;
using namespace std;

signed main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)>abs(x-b))cout<<"B"<<endl;
    else cout<<"A"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    ll N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v[i];
    sort(v.begin(), v.end());

    ll ans = 1e9+9;
    for(int i = 0; i < 100; i++) {
        ll tmp = 0;
        for (int j = 0; j < N; j++){
            tmp += (v[j] - i) * (v[j] - i);
            // cout << j << " " <<tmp << endl;
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = list(input())

count_0 = 0
count_1 = 0

for i in S:
	if i == "0":
		count_0 += 1
	if i == "1":
		count_1 += 1

print(min(count_0, count_1)*2)

Measured memory_bytes: 22800
#include <bits/stdc++.h>
using namespace std;
int main(){
    double a, b, x;
    cin>>a>>b>>x;
    double r;
    if(x <= a*a*b/2) r = atan2(b*b, 2*(x/a));
    else r = atan2(2*(a*b-(x/a)), a*a);
    double ans = r/(2*acos(-1)) * 360;
    cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 4128
#include <bits/stdc++.h>
using namespace std;
int V;
int MAXV = 1000;
vector<vector<int>> g(MAXV);
vector<int> match(MAXV);
vector<bool> used(MAXV);
void add_edge(int u, int v)
{
    g[u].push_back(v);
    g[v].push_back(u);
}
bool dfs(int v)
{
    used[v] = true;
    for(int u : g[v])
    {
        int w = match[u];
        if(w < 0 || (!used[w] && dfs(w)))
        {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}
int bipartite_matching()
{
    int res = 0;
    match.assign(MAXV, -1);
    for(int v = 0; v < V; v++)
    {
        if(match[v] < 0)
        {
            used.assign(MAXV, 0);
            if(dfs(v)) res++;
        }
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    vector<int> d(n);
    V = 2*n;
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    for(int i = 0; i < n; i++) cin >> c[i] >> d[i];
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(a[i] < c[j] && b[i] < d[j])
            {
                add_edge(i, j+n);
            }
        }
    }
    cout << bipartite_matching() << endl;
}




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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int n,k;
    cin >> n >> k;
    ll cnt = 1;
    cnt *= k;
    rep(i,n-1){
        cnt *= (k-1);
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
def solve():
    from sys import stdin
    f_i = stdin
    
    N, M = map(int, f_i.readline().split())
    A = tuple(map(int, f_i.readline().split()))
    
    from fractions import gcd
    def lcm(a, b):
        return a * b // gcd(a, b)
    
    import functools
    def mul_lcm(nums):
        return functools.reduce(lcm, nums)
    
    half_A = tuple((a // 2 for a in A))
    l = mul_lcm(half_A)
    
    for a in half_A:
        if (l // a) % 2 == 0:
            return 0
    
    return (M // l + 1) // 2

print(solve())

Measured memory_bytes: 14300
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;
static const int SIZE = 110000;
bool IsPrime[SIZE];
vector<int> Prime;

void calc()
{
	memset(IsPrime, 1, sizeof(bool) * SIZE);
	for(int i = 2; i < SIZE; ++i)
	{
		if(IsPrime[i])
		{
			Prime.push_back(i);
			for(int j = 2 * i; j < SIZE; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	calc();
	int n;
	while(cin >> n, n)
	{
		int sum = 0;
		for(int i = 0; i < n; ++i)
		{
			sum += Prime[i];
		}
		cout << sum << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define y1 stupid_cmath
#define left stupid_left
#define right stupid_right
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

int main(){

    vector<int> v;

    int n;
    int x;

    cin >> n;
    while (n--) {
        cin >> x;
        v.pb(x);
    }

    cout << *max_element(all(v)) - *min_element(all(v)) << endl;

    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    // Your code here!
    val list = listOf(1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)
    val k = readLine()!!.toInt()
    
    println(list[k-1])
}


Measured memory_bytes: 33836
#include<bits/stdc++.h>
using namespace std;
const int MX=(1<<20);
int a  = 0 , b = 0;
int main(){
    int x;
    cin>>x;
    if(x == 0){
        puts("0");
        return 0;
    }
    x = abs(x);
    for(int j = 1 ; ; j++){
        if(j * (j+1)/2 >= x){
            cout<<j<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
h, w = map(int, input().split())
s=[]
for i in range(h):
    s.append(list(input()))
 
l=[[0 for i in range(w)] for j in range(h)]
r=[[0 for i in range(w)] for j in range(h)]
u=[[0 for i in range(w)] for j in range(h)]
d=[[0 for i in range(w)] for j in range(h)]
for y in range(h):
    for x in range(w):
        if s[y][x] == '.':
            if x == 0:
                l[y][x]=1
            else:
                l[y][x]=l[y][x-1]+1
        
        if s[y][w-x-1] == '.':
            if x == 0:
                r[y][w-x-1]=1
            else:
                r[y][w-x-1]=r[y][w-x]+1
 
        if s[y][x] == '.':
            if y == 0:
                u[y][x]=1
            else:
                u[y][x]=u[y-1][x]+1
        
        if s[h-y-1][x] == '.':
            if y == 0:
                d[h-y-1][x]=1
            else:
                d[h-y-1][x]=d[h-y][x]+1
 
ans=0
for y in range(h):
    for x in range(w):
        val=l[y][x]+r[y][x]+u[y][x]+d[y][x]-3
        ans=max(ans, val)
 
print(ans)

Measured memory_bytes: 315016
S = input()
sign_list = []
count = 1


if S[0] == "<":
    flag = True
else:
    flag = False


S_dummy = S + "_"
for i in range(len(S_dummy) - 1):
    if S_dummy[i] == S_dummy[i + 1]:
        count += 1
    else:
        sign_list.append(count)
        count = 1


ans = 0
if flag:
    for i in range(len(sign_list) // 2):
        s_count = sign_list[i * 2]
        d_count = sign_list[i * 2 + 1]

        if s_count <= d_count:
            ans += d_count * (d_count + 1) / 2 + s_count * (s_count - 1) / 2
        else:
            ans += s_count * (s_count + 1) / 2 + d_count * (d_count - 1) / 2
    
    if len(sign_list) % 2 != 0:
        ans += sign_list[-1] * (sign_list[-1] + 1) / 2

else:
    ans += sign_list[0] * (sign_list[0] + 1) / 2

    for i in range((len(sign_list) - 1) // 2):
        s_count = sign_list[i * 2 + 1]
        d_count = sign_list[i * 2 + 2]

        if s_count <= d_count:
            ans += d_count * (d_count + 1) / 2 + s_count * (s_count - 1) / 2
        else:
            ans += s_count * (s_count + 1) / 2 + d_count * (d_count - 1) / 2
    
    if len(sign_list) % 2 == 0:
        ans += sign_list[-1] * (sign_list[-1] + 1) / 2


print(int(ans))

Measured memory_bytes: 6812