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

int main() {

    int n,r,dec=1,cnt=1;
    cin >> n;
    r=7%n;
    set<int> st;
    while(r!=0)
    {
        r=r*10+7;
        r=r%n;
        if(st.find(r)==st.end())
            st.insert(r);
        else
        {
            dec=0;
            break;
        }
        cnt++;

    }
    if(dec==0)
        cout << -1;
    else
        cout << cnt;

}


Measured memory_bytes: 50452
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  set<string> w;
  char e=s.at(s.size()-1);
  w.insert(s);
  bool f=1;
  for(int i=1;i<n;i++){
    cin>>s;
    if(e!=s.at(0)||w.count(s))
      f=0;
    e=s.at(s.size()-1);
    w.insert(s);
  }
  cout<<(f?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0

for i in range(n):
    ans += b[a[i]-1]
    if i < n-1 and a[i+1]-a[i] == 1:
        ans += c[a[i]-1]

print(ans)

Measured memory_bytes: 9128
n = int(input())

lst = []
for i in range(n):
    lst.append(list(map(int,input().split())))

out_list = [[0 for i in range(n)] for l in range(n)]

for a,in_lst in enumerate(lst):
    for x in range(in_lst[1]):
        out_list[a][in_lst[x+2]-1] = 1


for o1 in out_list:
    print(' '.join([str(x) for x in o1]))



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

int main()
{
    int a, b, ans;
    cin >> a >> b;
    if (b % a == 0)
        ans = a + b;
    else
    {
        ans = b - a;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] hw = br.readLine().split(" ");
        int h = Integer.parseInt(hw[0]);
        int w = Integer.parseInt(hw[1]);
        char[][] grid = new char[h+2][w+2];
        
        for (int i = 1; i <= h; i++) {
            String line = br.readLine();
            for (int j = 1; j <= w; j++) {
                grid[i][j] = line.charAt(j-1);
            }
        }
        
        boolean possible = true;
        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                if (grid[i][j] == '#') {
                    if (grid[i-1][j] == '.' && grid[i][j+1] == '.' && grid[i+1][j] == '.' && grid[i][j-1] == '.') possible = false;
                }
                else continue;
            }
        }
        
        if (possible) System.out.println("Yes");
        else System.out.println("No");
    }
}


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

typedef long long ll;
int main(){
  int n;
  cin >> n;
  vector<ll>ar(n);
  for(int i = 0; i < n; i++){
    ll a;cin>>a;
    ar[i]=a-i-1;
  }
  sort(ar.begin(),ar.end());
  ll ans=0;
  if(n%2)
  {
      ll b=ar[n/2];
      for(int i=0;i<n;i++)
        {ans+=abs(ar[i]-b);}
    cout<<ans<<endl;
  }
  else
  {
     ll b1=ar[n/2-1];
     ll b2=ar[n/2];
     //cout<<b1<<" "<<b2<<endl;
     ll ans1=0;
     for(int i=0;i<n;i++)
        {ans+=abs(ar[i]-b1);ans1=abs(ar[i]-b2);}
    cout<<max(ans,ans1)<<endl;
  }
}
    
    


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<map>
#include<vector>
#include<queue>
using namespace std;
map<long long, priority_queue<int > >a;
//priority_queue<int > a[1005];
int main()
{
    int n, q;
    int x, z;
    long long y;
    cin >> n >> q;
    
        for (int i = 0; i < q; i++)
        {
            cin >> x >> y;
            switch (x)
            {
            case(0):
                scanf("%d", &z);
                a[y].push(z);
                break;
            case(1):
                if (!a[y].empty())
                {
               printf("%d\n", a[y].top());
                }
                break;
            case(2):
                if (!a[y].empty())
                {
                a[y].pop();
                }

                break;
            default:
                break;
            }
        }
    


    return 0;
}



Measured memory_bytes: 4288
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

bool dp[100010];

int main(){

  int n, k;
  cin >> n >> k;

  vector<int> v(n);
  REP(i,n){
    cin >> v[i];
  }

  REP(j,k+1){
    REP(i,n){
      if(j + v[i] <= k) dp[j + v[i]] |= !dp[j];
    }
  }

  if(dp[k]){
    cout << "First\n";
  }else{
    cout << "Second\n";
  }

  return 0;
}



Measured memory_bytes: 1016
// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll lg=22;
const ll N=2e5+5;
const ll M=5e8;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
 
inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }
 
#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

ll n,m,a[55][55],b[55][55];

int main()
{
    ll n;
    cin>>n;
    ll a[n],cnt=0;
    for(ll i=0;i<n;i++){cin>>a[i];}
    for(ll i=1;i<n-1;i++)
    {
        vector<ll> v;
        v.pb(a[i]);
        if(i-1>=0){v.pb(a[i-1]);}
        if(i+1<n){v.pb(a[i+1]);}
        sort(all(v));
        cnt+=(v[1]==a[i]);
        //if(v[1]==a[i]){cout<<i<<" "<<a[i]<<endl;}
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int main() {
	int a, b, c; cin >> a >> b >> c;
	cout << (a < b && b < c ? "Yes" : "No") << endl;
}

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

int main() {
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N;
  cin>>N;

  string S;
  cin>>S;

  int K;
  cin>>K;

  for(int i=0;i<S.size();i++){
    if(S.at(i)!=S.at(K-1)) S.at(i)='*';
  }
  cout<<S<<endl;

}


Measured memory_bytes: 256
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N)]

dp = [[0, 0, 0] for _ in range(N + 1)]

for n, p in enumerate(ABC):
	dp[n + 1][0] = max(dp[n + 1][0], dp[n][1] + p[0], dp[n][2] + p[0])
	dp[n + 1][1] = max(dp[n + 1][1], dp[n][0] + p[1], dp[n][2] + p[1])
	dp[n + 1][2] = max(dp[n + 1][2], dp[n][0] + p[2], dp[n][1] + p[2])

#for line in dp:
#	print(*line)

print(max(dp[-1]))


Measured memory_bytes: 47344
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
	ll n;
	cin >> n;
	ll cnt = 0;
	PREP(i, 1, n){
		cnt += (n-1)/i;
	}
	cout << cnt << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
bool compare_by_a(pair<int, pair<ll, ll>> a, pair<int, pair<ll, ll>> b) {
    if(a.second.first != b.second.first){
        return a.second.first < b.second.first;
    }else{
        return a.second.second < b.second.second;
    }
}
bool compare_by_b(pair<int, pair<ll, ll>> a, pair<int, pair<ll, ll>> b) {
    if(a.second.second != b.second.second){
        return a.second.second < b.second.second;
    }else{
        return a.second.first < b.second.first;
    }
}
template<typename T>
struct edge {
    int from, to; // クラスカル法に限って、fromもedgeに含めるといい
    T cost;
};
// UnionFindを示す構造体
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
template<typename T>
T kruskal(vector<edge<T>> &edges, int V) {
    sort(edges.begin(), edges.end(), [](const edge<T> &a, const edge<T> &b) {
        return a.cost < b.cost;
    });
    UnionFind unionFind(V);
    T res = 0;
    for (edge<T> &e: edges) {
        if (unionFind.merge(e.to, e.from)) {
            res += e.cost;
        }
    }
    return res;
}

const ll INF = 1e18;
int main() {
  int V, E; cin >> V >> E;
  vector<vector<ll>> D(V, vector<ll>(V, INF));
  REP(i, E) {
    int s, t, d; cin >> s >> t >> d;
    D[s][t] = d; // 有向グラフのため片方のみGに登録する
  }
  REP(i, V) {
    D[i][i] = 0;
  }
  for (int k = 0; k < V; k++){       // 経由する頂点
    for (int i = 0; i < V; i++) {    // 始点
      for (int j = 0; j < V; j++) {  // 終点
        D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
      }
    }
  }
  bool flag = false;
  for(int i = 0; i < V; ++i) {
    if(D[i][i] != 0) flag = true;
  }
  if(!flag) {
    REP(i, V) {
      REP(k, V) {
        if(D[i][k] >= 1e17) cout << "INF";
        else cout << D[i][k];
        if(k != V - 1) cout << " ";
      }
      cout << endl;
    }
  } else {
    cout << "NEGATIVE CYCLE" << endl;
  }
}


Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;
  cin>>s;
  vector<int> A(1000000);
  A[0]=s;
  for(int i=1;i<1000000;i++){
  A[i]=A[i-1];
    if(A[i]%2==0){
    A[i]=A[i]/2;
    }
    else{
    A[i]=3*A[i]+1;
    }
  }
   for(int i=0;i<1000000;i++){
      for(int j=1;j<1000000;j++){
        if(j>i&&A[i]==A[j]){
        cout<<j+1<<endl;
          return 0;
        }
      }
   }
}

Measured memory_bytes: 4096
n = int(input())
s = input()

count_w = s.count('.')
count_b = 0
ans = count_w + count_b

for si in s:
    if si == '.':
        count_w -= 1
    else:
        count_b += 1
    now = count_w + count_b
    if now < ans:
        ans = now

print(ans)

Measured memory_bytes: 3500
h, w = map(int, input().split())
table = []
for i in range(h):
    table.append(list(input()))
poss = True
for i in range(h-1):
    for j in range(w-1):
        if table[i][j] == "#":
            if (table[i+1][j]=="#" and table[i][j+1]=="#") or (table[i+1][j]=="." and table[i][j+1]=="."):
                poss = False
for i in range(1, h):
    if table[i][w-2]=="#" and table[i-1][w-1]=="#":
        poss = False
for i in range(1, w):
    if table[h-1][i-1]=="#" and table[h-2][i]=="#":
        poss = False

if poss:
    print("Possible")
else:
    print("Impossible")


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

const int N = 100005;

int k, vis[N], dist[N];

int main(){
    scanf("%d", &k);

    // 확장된 BFS 알고리즘 수행을 위한 초기화
    queue<int> q[2];
    for(int i = 0; i < k; i++) dist[i] = k;
    dist[1] = 0;
    q[0].push(1);

    int cdist = 0;
    while(cdist < k){
        while(cdist < k && q[cdist % 2].empty()) cdist++; // 비어 있지 않은 Queue를 찾는다.
        if(cdist == k) break; // 더 이상 탐색할 정점이 없음

        int cur = q[cdist % 2].front();
        q[cdist % 2].pop();
        // 각 정점당 최대 한 번만 처리하게 하기 위함.
        // 다익스트라 알고리즘의 구현과 달리, Queue에 거리 정보를 같이 넣지 않으므로
        // visit 배열을 통해 구현함.
        if(vis[cur]) continue;
        vis[cur] = 1;

        // +1의 경우 (가중치 1)
        int plus = (cur + 1) % k;
        if(dist[plus] > dist[cur] + 1){
            dist[plus] = dist[cur] + 1;
            q[dist[plus] % 2].push(plus);
        }

        // *10의 경우 (가중치 0)
        int mult = cur * 10 % k;
        if(dist[mult] > dist[cur]){
            dist[mult] = dist[cur];
            q[dist[mult] % 2].push(mult);
        }
    }

    printf("%d\n", dist[0] + 1);
}

Measured memory_bytes: 1280
S=gets.chomp.split('')
if(S.size==1)
	puts 1
	exit(0)
end
h = {}
sum = 0
for i in 0..(2**(S.size-1)-1)
	# ignore exp==S.size-1
	s = S.each_with_index.map{|d,exp| d + (i & 2**exp != 0 ? "+" : "")}
	# puts s.join("")
	sum += eval(s.join(""))
end
puts sum


Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
int main()
{
 ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  long long k;
  int n;
  
  cin>>k>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  int d;
  d=k-a[n-1]+a[0];
  for(int i=0;i<n-1;i++)
  {
    if(d<(a[i+1]-a[i]))
      d=a[i+1]-a[i];
  }
  cout<<(k-d);
  return 0;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG//実行時、何も出なかったらこれを使う
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>
#include<limits>//
#include <stdio.h>//
#include<cmath>
#include<iomanip>

using namespace std;

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

typedef long long ll;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

int dy[] = {1,0,-1,0}; //次に行くところ
int dx[] = {0,1,0,-1}; //s上に同じ

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a,b,c,k;
  ll ans = 0;
  cin >> a >> b >> c >> k;
  for (int i = 0; i < k; i++){
    if (a != 0){
      ans++;
      a--;
      continue;
    }
    if (b != 0){
      b--;
      continue;
    }
    ans--;
    c--;
  }
  
  cout << ans << "\n";
  
  return 0;
}

Measured memory_bytes: 3648
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N, K;
    std::cin >> N >> K;
    std::vector<int64_t> p(N);
    for (auto& v : p) std::cin >> v;

    std::sort(p.begin(), p.end());
    int64_t ans = 0;
    for (int64_t i = 0; i < K; i++)
    {
        ans += p[i];
    }

    std::cout << ans << std::endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  
  int result = 0;
  bool beforeIsR = false;
  for(int i=0; i<(int)s.length(); i++){
    if(!beforeIsR && s[i] == 'R'){
      result = 1;
      beforeIsR = true;
    }else if(beforeIsR && s[i] == 'R'){
      result++;
      beforeIsR = true;
    }else{
      beforeIsR = false;
    }
  }

  cout << result << endl;

  return 0;
}

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

using namespace std;

int main()
{
	int a;
	int b;
	cin >> a >> b;
	if(a > 0)
	{
		cout << "Positive";
	}
	if(a < 0 && b > 0)
	{
		cout << "Zero";
	}
	if(b < 0)
	{
		if ((b - a + 1) % 2 == 1)
			cout << "Negative";
		else
			cout << "Positive";
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    int n, zero = 0, two = 0, four = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        if (t % 4 == 0)four++;
        else if (t % 2 == 0)two++;
        else zero++;
    }
    if (zero == four+1) {
        if (two == 0)Yes;
        else No;
    }
    else if (zero > four+1)No;
    else Yes;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int A[30], n;
struct DP {
	bool isSloved = false;
	bool res = false;
};

DP dp[25][2100];

bool slove(int i, int m) {
	if (dp[i][m].isSloved)
		return dp[i][m].res;

	if (m == 0) {
		dp[i][m].res = true;
		dp[i][m].isSloved = true;
	}
	else if (i >= n) {
		dp[i][m].res = false;
		dp[i][m].isSloved = true;
	}
	else if (slove(i + 1, m)) {
		dp[i][m].res = true;
		dp[i][m].isSloved = true;
	}
	else if (slove(i + 1, m - A[i])) {
		dp[i][m].res = true;
		dp[i][m].isSloved = true;
	}
	else {
		dp[i][m].res = false;
		dp[i][m].isSloved = true;
		return false;
	}
	return dp[i][m].res;
}

signed main() {
	ios::sync_with_stdio(false);
	int q, i, M;
	cin >> n;
	for (i = 0; i < n; i++) cin >> A[i];
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> M;
		if (slove(0, M)) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}


Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int MAX_N = (1 << 21) - 1;
const ll inf = numeric_limits<ll>::max()/3;

int main(void){
  int n,m,c;
  cin >> n >> m >> c;
  map<int,int> upper_c;
  vector< P > items;
  for(int i = 0;i < c;++i){
    int l;
    cin >> l;
    upper_c[i+1] = l;
  }
  for(int i = 0;i < n;++i){
    ll col,w;
    cin >> col >> w;
    items.push_back(P(w,col));
  }
  sort(items.begin(),items.end(),greater<P>());
  int cnt = 0;
  ll res = 0;
  for(int i = 0;i < n;++i){
    if(cnt == m)break;
    ll ncol,nw;
    tie(nw,ncol) = items[i];
    if(upper_c[ncol] == 0)continue;
    res += nw;
    --upper_c[ncol];
    ++cnt;
  }
  cout << res << endl;
  return 0;
}



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

int max(int a, int b){
	return (a>b)? a: b;
}

using namespace std;

int main(){
	int N;
	int W;
	cin >> N >> W;
	int v[N+1];
	int w[N+1];

	for(int i = 1; i < N+1; i++) cin>> v[i] >> w[i];
	

	int dp[N+1][W+1];
	for(int i = 0; i < W+1; i++) dp[0][i] = 0;
	for(int i = 0; i < N+1; i++) dp[i][0] = 0;

	for(int ni = 1; ni < N+1; ni++){
		for(int wi = 1; wi < W+1; wi++){
			dp[ni][wi] = (wi >= w[ni])? max(v[ni]+dp[ni-1][wi-w[ni]], dp[ni-1][wi]): dp[ni-1][wi];
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}

Measured memory_bytes: 5104
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int a=0,k=0,pre=0;
		if(n==0) break;
		string f;
		for(int i=0;i<n;i++){
			cin>>f;
			if(f=="lu") a=a+1;
			if(f=="ld") a=a-1;
			if(f=="ru") a=a+10;
			if(f=="rd") a=a-10;
			if(pre==0&&a==11){
				k++;
				pre=11;
			}
			if(pre==11&&a==0){
				k++;
				pre=0;
			}
		}
		cout<<k<<endl;
	}
    return 0;
}

Measured memory_bytes: 1212
s=input();a,b,c=[0,0,0]
for i in range(len(s)):
    if s[i]=='a':
        a+=1
    elif s[i]=='b':
        b+=1
    else:
        c+=1
N=len(s)
print("YES" if max(a,b,c)-min(a,b,c)<=1 and a>=N//3 and b>=N//3 and c>=N//3 else "NO")

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL
#define DEBUG

typedef struct node{
  struct node* parent;
  struct node* left;
  struct node* right;
  int k;
}Node;

Node* tree;

void insert(int);
void inorder(Node*);
void preorder(Node*);

int main(){
  int m,i,k;
  char s[10];

  scanf("%d",&m);
  
  for(i=0;i<m;i++){
    scanf("%s",s);
    if(s[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    else if(s[0]=='p'){
      inorder(tree);
      printf("\n");
      preorder(tree);
      printf("\n");
    }
  }

  return 0;
}

void insert(int k){
  Node* y = NIL;
  Node* x = tree;
  Node* z;
  z=(Node *)malloc(sizeof(Node));
  z->k=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->k < x->k ){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;

  if(y==NIL) tree=z;
  else if(z->k < y->k) y->left=z;
  else y->right=z;
  return;
}

void inorder(Node* tree){
  if(tree != NIL){
    inorder(tree->left);
    printf(" %d",tree->k);
    inorder(tree->right);
  }
  return;
}

void preorder(Node* tree){
  if(tree != NIL){
    printf(" %d",tree->k);
    preorder(tree->left);
    preorder(tree->right);
  }
  return;
}

Measured memory_bytes: 24040
import java.util.Scanner;                                                                        
class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(true){
            int m = in.nextInt();
            int f = in.nextInt();
            int r = in.nextInt();
            int g = m+f;
        if(m == -1 && f == -1 && r == -1){
            break;
        }
        if(m == -1 | f == -1){
            System.out.println("F");
        }else if(g >= 80 ){
            System.out.println("A");
        }else if(g >= 65 && g <= 79){
            System.out.println("B");
        }else if(g >= 50 && g <= 64){
            System.out.println("C");
        }else if(g >= 30 && g <= 49){
            if(r >= 50){
                System.out.println("C");
            }else{
                System.out.println("D");
            }
        }else{
        System.out.println("F");
        }
    }
    }
}                

Measured memory_bytes: 26040
#include<stdio.h>

int main(){
  int N,A,B;
  scanf("%d %d %d",&N,&A,&B);

  int i;
  int total=0;
  for(i=1;i<=N;i++){
    int t1=i%10;
    int t2=i/10;
    while(t2!=0){
      t1=t1+t2%10;
      t2=t2/10;
    }
    if(A<=t1 && t1<=B){
      total+=i;
    }
  }
  printf("%d",total);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a,b,c,t,k,ans;
int main(void)
{
    scanf("%d %d %d",&a,&b,&c);
    scanf("%d",&k);
    t = max({a,b,c});
    ans=a+b+c-t;
    for(int i=1;i<=k;i++) t*=2;
    ans+=t;
    printf("%d",ans);
}


Measured memory_bytes: 256
N_K=list(map(int,input().split()))
N=N_K[0]
K=N_K[1]
cost=list(map(int,input().split()))
answers=[0,abs(cost[1]-cost[0])]
if K==1:
	S=0
	for i in range(N-1):
		S += abs(cost[i]-cost[i+1])
	print (S)
else:
	for i in range(2,N):
		comp=[]
		if i<K:
			comp=[answers[i-j]+abs(cost[i]-cost[i-j]) for j in range(1,i+1)]
			answers.append(min(comp))
		else:
			comp=[answers[i-j]+abs(cost[i]-cost[i-j]) for j in range(1,K+1)]
			answers.append(min(comp))			
	print(answers[-1])

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

const int MOD = (int)1e9+7;

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

	for(int i=0;i<s.size()-1;i++){
		if(s.at(i)==s.at(i+1)){
			cout << i+1 << " " << i+2 << endl;
			return 0;
		}
	}
	for(int i=0;i<s.size()-2;i++){
		if(s.at(i)==s.at(i+2)){
			cout << i+1 << " " << i+3 << endl;
			return 0;
		}
	}
	cout << "-1 -1" << endl;
	
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n;
    cin>>n;
    Vi d(n);
    REP(i,0,n) cin>>d[i];
    sort(ALL(d));

    map<int,int> ma;
    REP(i,0,n) ma[d[i]]++;
    for(auto x : ma) if(x.second>2) {cout<<0<<endl; return 0;}

    Vi b;
    b.pb(0);
    b.pb(24);
    REP(i,0,n){
        if(i%2==0) b.pb(d[i]);
        else b.pb(24-d[i]);
    }
    sort(ALL(b));

    int ans=INF;
    REP(i,0,b.size()-1){
        chmin(ans,b[i+1]-b[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
s = stdin.readline().rstrip()
for i in range(8):
    point = int(s[0])
    sin = s[0]
    for j in range(3):
        if ((i >> j) & 1):
            point += int(s[j+1])
            sin += "+"+s[j+1]
        else:
            point -= int(s[j+1])
            sin += "-"+s[j+1]
    if point == 7:
        print(sin+"=7")
        exit()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define ios; ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef double db;
mt19937 rnd(random_device{}());
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
const int M = 1e3 + 5;
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
inline ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
ll n, m, k;

int main(){
    ios;
    ll ans=0;
    cin>>n>>k;
    rep(i,1,n){
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=k*k) ++ans;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int N=100005;
const int MOD=1000000007;

int n,f[N],g[N];
LL a,b,s[N];

int main()
{
	scanf("%d%lld%lld",&n,&a,&b);
	if (a>b) swap(a,b);
	for (int i=1;i<=n;i++) scanf("%lld",&s[i]);
	sort(s+1,s+n+1);
	for (int i=3;i<=n;i++) if (s[i]-s[i-2]<a) {puts("0");return 0;}
	f[0]=g[0]=1;int p=0,lim=0;
	for (int i=1;i<=n;i++)
	{
		while (p<i&&s[i]-s[p+1]>=b) p++;
		if (lim<=p) f[i]=(g[p]+MOD-(lim?g[lim-1]:0))%MOD;
		g[i]=(g[i-1]+f[i])%MOD;
		if (i>1&&s[i]-s[i-1]<a) lim=i-1;
	}
	int ans=0;
	for (int i=n;i>=0;i--)
	{
		(ans+=f[i])%=MOD;
		if (i<n&&s[i+1]-s[i]<a) break;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long a[100];
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    /* code */
    std::cin >> a[i];
  }
  sort(a,a+n);
  std::cout << abs(a[0]-a[n-1]) << std::endl;
}

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define pb push_back

using namespace std;

typedef unsigned long long LL;

LL N;

int main(){
	cin >> N;
	// 4 * i * j - j * N - i * N / N * i * j
	For(i, 1, 3500) For(j, i, 3500){
		LL x = 4 * i * j - j * N - i * N;
		if(x <= 0) continue;
		LL y = N * i * j;
		if(y % x == 0){
			printf("%d %d %lld\n", i, j, y / x);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
    int n;
    scanf("%d", &n);
    int a,b,c =0,aux;
    for (int i = 0; i < n; i++) {
        scanf("%d %d\n",&a, &b);
        if (a < b) {
            aux = a;
            a = b;
            b = aux;
        }
        c+=a-b + 1;
    }
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back

#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

signed main()
{
    int n;cin>>n;
    std::vector<string> inp(n);
    for(int i=0;i<n;++i){cin>>inp[i];sort(inp[i].begin(),inp[i].end());}
    sort(inp.begin(),inp.end());
	
	int pres=1,ans=0;
	for(int i=1;i<n;++i)
	{
		if(inp[i]==inp[i-1]){++pres;}
		else
		{
			ans+=((pres*(pres-1))/2);
			pres=1;
		}
	}
	ans+=((pres*(pres-1))/2);
	cout<<ans<<"\n";
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;



void solve(){
    string s;
    cin>>s;
    f(i,s.length())cout<<"x";
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

A = []

B = ['.'] * (w + 2)
A.append(B)
for i in range(h):
    C = list(input())
    C = ['.'] + C + ['.']
    A.append(C)
A.append(B)

ans = 1
for i in range(1, h+1):
    for j in range(1, w+1):
        if A[i][j] == '#':
            D = [A[i - 1][j], A[i][j - 1], A[i][j + 1], A[i + 1][j]]
            if '#' in D:
                continue
            else:
                ans = 0
                break

if ans:
    print("Yes")
else:
    print("No")

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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  sort(S.begin(), S.end());
  sort(T.rbegin(), T.rend());
  if (S < T) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int a[n+1];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    float temp=float(a[0]);
    for(int i=1;i<n;i++)
    {
       float t=(float)(temp+a[i])/2;
       temp=t;
    }
    cout<<temp<<endl;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define int long long

// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define all(v) v.begin(), v.end()
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())

// chmax, chmin
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << (x) << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  solve();
  return 0;
}

void solve() {
  int a, b;
  std::string s;
  std::cin >> a >> b >> s;

  if (SIZE(s) != a + b + 1) {
    cout(no);
    return;
  }

  REP(i, a + b + 1) {
    if (i == a) {
      if (s.at(i) != '-') {
        cout(no);
        return;
      }
    } else {
      if (s.at(i) < 48 || s.at(i) > 57) {
        cout(no);
        return;
      }
    }
  }
  cout(yes);
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
std::vector<int> p;
int n,m,ans;
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i*i<=m;i++)
	    if (m%i==0)
	    {
		    p.push_back(i);
		    if (i*i!=m) p.push_back(m/i); 
	    }
	for (int i=0;i<p.size();i++) if (p[i]>ans&&1ll*p[i]*n<=m) ans=p[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define pii pair<int , int>
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
const int INF = 1000 * 1000 * 1000 + 7;
const ll LINF = INF * (ll)INF;
const int mod = 998244353;
const int MAX = 2000005;

int main()
{
	ios_base::sync_with_stdio(0);
	int r, c;
	cin >> r >> c;
	if(r == 1 || c == 1)
	{
		cout << 1;
		return 0;
	}
	cout << (r * (ll)c + 1) / 2;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int H,W,h,w;cin>>H>>W>>h>>w;
    cout<<H*W-H*w-h*W+h*w<<endl;
}


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

#define int long long 

const int MOD = 1e9 + 7;

int add(int a, int b) {
	a += b;
	if (a < 0) a += MOD;
	if (a > MOD) a -= MOD;
	return a;
}

int mul(int a, int b) {
	return (a * 1ll * b) % MOD;
}

int power(int a, int b) {
	int res = 1ll;
	while (b) {
		if (b & 1) {
			res = mul(res, a);
		}
		a = mul(a, a), b >>= 1;
	}
	return res;
}

int modinv(int a) {
	return power(a, MOD - 2);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int n; cin >> n;
    vector<int> v(n);
    for (auto& iter : v) {
    	cin >> iter;
    }
    int square_of_sum = 0ll;
    int sum_of_squares = 0ll;
    for (auto iter : v) {
    	sum_of_squares += (iter * iter);
    	sum_of_squares %= MOD;
    	square_of_sum += iter;
    	square_of_sum %= MOD;
    }
    square_of_sum = power(square_of_sum, 2);
    int ans = square_of_sum;
    ans -= sum_of_squares;
    if (ans < 0) ans += MOD;
    ans *= modinv(2); ans %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()

int main(void){
    int a,b,cnt=0;
    cin>>a>>b;
    for(int i=a;i<=b;i++){
        string s1 = to_string(i);
        string s2 = s1;
        reverse(all(s2));
        if(s1==s2)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i) // ROF(i,n,0)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define SUM(a) accumulate(all(a),int(0))
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

signed main(){
  int n, d; cin >> n >> d;
  d = 2 * d + 1;
  cout << (n+d-1)/d << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
Scanner s = new Scanner(System.in);
		int H = Integer.valueOf(s.next());
		int W = Integer.valueOf(s.next());
		int[] start = new int[4]; //y, x, 歩数, ワープ
		int[] goal = new int[2];
		start[0] = Integer.valueOf(s.next()) - 1;
		start[1] = Integer.valueOf(s.next()) - 1;
		goal[0] = Integer.valueOf(s.next()) - 1;
		goal[1] = Integer.valueOf(s.next()) - 1;

		int[][] maze = new int[H][W];
		char[] cur;
		for(int i = 0; i < H; i++) {
			cur = s.next().toCharArray();
			for(int j = 0; j < W; j++) {
				maze[i][j] = cur[j] == '.' ? -1 : -2;
			}
		}

		int[] vx = {1, 0, -1, 0};
		int[] vy = {0, -1, 0, 1};
		int[][] vxw = new int[4][5];
		int[][] vyw = new int[4][5];

		vxw[0] = new int[]{2, 2, 2, 2, 2}; //20個
		vyw[0] = new int[]{2, 1, 0, -1, -2}; //20個
		vxw[1] = new int[]{1, 1, 0, -1, -1}; //20個
		vyw[1] = new int[]{-1, -2, -2, -2, -1}; //20個
		vxw[2] = new int[]{-2, -2, -2, -2, -2}; //20個
		vyw[2] = new int[]{-2, -1, 0, 1, 2}; //20個
		vxw[3] = new int[]{-1, -1, 0, 1, 1}; //20個
		vyw[3] = new int[]{1, 2, 2, 2, 1}; //20個

		PriorityQueue<int[]> Q = new PriorityQueue<>((a, b) -> Integer.compare(a[3], b[3]));
		Q.add(start);

		int[] now;
		int[] tmp = new int[4];
		int ret = -1;
		while(!Q.isEmpty()) {
			now = Q.poll();

			for(int i = 0; i < 4; i++) {
				tmp[0] = now[0] + vy[i];
				tmp[1] = now[1] + vx[i];

				// 範囲内チェック
				if(-1 < tmp[0] && tmp[0] < H && -1 < tmp[1] && tmp[1] < W) {

					// 一回も行ってない
					if(maze[tmp[0]][tmp[1]] > now[3] || maze[tmp[0]][tmp[1]] < 0) {

						// 迷路が壁以外
						if(maze[tmp[0]][tmp[1]] != -2) {

							// ゴール
							if(tmp[0] == goal[0] && tmp[1] == goal[1]) {
								System.out.println(now[3]);
								return;
							}

							maze[tmp[0]][tmp[1]] = now[3]; // 迷路の値を更新
							Q.add(new int[] {tmp[0], tmp[1], 0, now[3]});

						// 迷路が壁
						}else {

							for(int j = 0; j < 5; j++) {
								tmp[0] = now[0] + vyw[i][j];
								tmp[1] = now[1] + vxw[i][j];

								// 範囲内チェック
								if(-1 < tmp[0] && tmp[0] < H && -1 < tmp[1] && tmp[1] < W) {

									// 一回も行ってない
									if(maze[tmp[0]][tmp[1]] > now[3] || maze[tmp[0]][tmp[1]] < 0) {
										// 迷路が壁以外
										if(maze[tmp[0]][tmp[1]] != -2) {

											// ゴール
											if(tmp[0] == goal[0] && tmp[1] == goal[1]) {
												System.out.println(now[3] + 1);
												return;
											}
											maze[tmp[0]][tmp[1]] = now[3] + 1; // 迷路の値を更新
											Q.add(new int[] {tmp[0], tmp[1], 0, now[3] + 1});
											j++;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		System.out.println(ret);
	}
}

Measured memory_bytes: 66128
s = input()
if s[0] !='A':
    print('WA')
    exit()
if 'C' not in s[2:len(s)-1]:
    print('WA')
    exit()
cnt = 0
for i in s:
    if i.isupper():
        cnt +=1
if cnt !=2:
    print('WA')
    exit()
print('AC')


Measured memory_bytes: 9044
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef int keytype;

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

/* a[0], ..., a[n-1] の数の最大公約数 */
int ngcd(int n, int a[])
{
    int i, d;

    d = a[0];
    for (i = 1; i < n && d != 1; i++)
        d = gcd(a[i], d);
    return d;
}

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

//#define N 5
//int p[N + 1];
int nextperm(int p[], int N)  /* 辞書式順序で次の順列 */
{
    int i, j, t;

    i = N - 1;
    p[0] = 0;  /* 番人 */
    while (p[i] >= p[i + 1]) i--;
    if (i == 0) return 0;  /* 完了 */
    j = N;
    while (p[i] >= p[j]) j--;
    t = p[i];  p[i] = p[j];  p[j] = t;
    i++;  j = N;
    while (i < j) {
        t = p[i];  p[i] = p[j];  p[j] = t;  i++;  j--;
    }
    return 1;  /* 未了 */
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

int min(int a, int b){
    if(a > b) return b;
    else return a;
}

const int inf = 1012345678;
int main(){
    int n, d;
    int x[100][100];

    scanf("%d %d", &n, &d);
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < d; ++j){
            scanf("%d", &x[i][j]);
        }
    }

    int cnt = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            int sum = 0;
            for(int k = 0; k < d; ++k){
                sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            for(int k = 1; k <= 130; ++k){
                if(sum == (k * k)){
                    cnt++;
                }
            }
        }
    }

    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 1736