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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<vector<ii>> test(n);
	for (int i=0; i<n; i++) {
		int a; cin>>a;
		for (int j=0; j<a; j++) {
			int x,y; cin>>x>>y; x--;
			test[i].push_back({x,y});
		}
	}

	int ret=-1;
	for (int bt=0; bt<(1<<n); bt++) {
		bool ok=true;
		int cur=0;
		vector<int> col(n,-1);
		for (int i=0; i<n; i++) {
			if(bt&(1<<i)) {
				cur++;
				if(col[i]==-1) col[i]=1;
				else {
					if(col[i]!=1) {
						ok=false;
						break;
					}
				}
				for (auto it : test[i]) {
					if(col[it.first]==-1) col[it.first]=it.second;
					else {
						if(col[it.first]!=it.second) {
							ok=false;
							break;
						}
					}
				}
			}
		}
		queue<int> q;
		for (int i=0; i<n; i++)
			if(col[i]==1)
				q.push(i);
		while(!q.empty()) {
			int cur=q.front(); q.pop();
			for (auto it : test[cur]) {
				if(col[it.first]==-1) {
					col[it.first]=it.second;
					q.push(it.first);
				} else {
					if(col[it.first]!=it.second) {
						ok=false;
						break;
					}
				}
			}
		}

		if(ok)
			ret=max(ret,cur);
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S) #lenはリアル個数を出力
ans = ""
for i in range(N // 2):
    if S[0 + i] == S[(N - 1) - i]:
        ans = "Yes"
    else:
        ans = "No"
        break
    if S[0 + i] == S[((N - 1) // 2) - 1 - i]:
        ans = "Yes"
    else:
        ans = "No"
        break
    if S[((N + 3) // 2) - 1 + i] == S[(N - 1) - i]:
        ans = "Yes"
    else:
        ans = "No"
        break
print(ans)

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

int even(string line)
{
	int len = line.size();
	int l = (len-2)/2, i;
	while (l)
	{
		for (i = 0; i < l; i++)
		{
			if (line[i] != line[l + i])
			{
				l -= 1; i = 0;
			}
		}
		if (l) return 2 * l;
	}
	return 0;
}
int main()
{
	string line;
	while (getline(cin,line))
	{
		cout << even(line) << endl;

	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int five = 0;
        int seven = 0;
        for(int i = 0; i < 3; i++) {
            int num = sc.nextInt();
            if(num == 5)
                five++;
            else if(num == 7)
                seven++;
        }
        if(five == 2 && seven == 1)
        System.out.println("YES");
        else
        System.out.println("NO");
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000009;
const double pi = acos(-1);

int main() {
    string S,T; cin >> S >>T ;
    int ans = 1e9;
    int N = S.size();
    int M = T.size();
    if(N == M) {
        int cnt = 0;
        REP(j,M) {
                cnt += (S[j] != T[j]);
            }
            chmin(ans,cnt);
    } else {
        REP(i,N-M) {
            int cnt = 0;
            REP(j,M) {
                cnt += (S[i+j] != T[j]);
            }
            chmin(ans,cnt);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	string s;
	unsigned long long k, cnt = 0;
	in(s);
	in(k);

	rep(i, 0, s.size()) {
		if (s[i] != '1') {
			outn(s[i]);
			return 0;
		}
		else if(i==k-1) {
			outn('1');
			return 0;
		}
	}

	return 0;

}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N, M;
	cin >> N >> M;
	int ans = 0;
	ans = (N - M) * 100;
	ans += M * 1900;
	for (int i = 0; i < M; i++) ans *= 2;
	cout << ans << endl;
}


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

int main () {
    int n, y;
    cin >> n >> y;
    int a, b;

    for (a = 0; a <= n; a++) {
        for (b = 0; b <= n - a; b++) {
            if (a * 1000 + b * 5000 + (n - a - b) * 10000 == y) {
                cout << n - a- b << " " << b << " " << a << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
    return 0;
}

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

using namespace std;

int main()
{
  string str, od, rep, rev;
  int n;

  cin >> str >> n;

  for (int i = 0; i < n; i++)
  {
    cin >> od;
    int a, b;
    if (od == "print")
    {
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
      continue;
    }
    else if (od == "reverse")
    {
      cin >> a >> b;
      reverse(str.begin() + a, str.begin() + b + 1);
      continue;
    }
    else if (od == "replace")
    {
      cin >> a >> b >> rep;
      str.replace(a, b - a + 1, rep);
      continue;
    }
  }
}


Measured memory_bytes: 3204
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  string s,t;cin>>s>>t;
  sort(s.begin(),s.end());sort(t.begin(),t.end());
  bool ok=false;
  rep(i,0,t.size()){
    if(t[i]>s[0]){ok=true;break;}
  }
  if(!ok){
    if(t[t.size()-1]==s[s.size()-1]&&t.size()>s.size()){ok=true;}
  }
  if(ok){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}



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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
//const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  string S;
  cin >> S;
  int sum = 0;
  for(auto &c : S) sum += c - '0';
  if(sum % 9 == 0) cout << "Yes\n";
  else cout << "No\n";
}



Measured memory_bytes: 3740
import sys

def parent(i, *d):
    tmp = i/2
    if tmp <=0 or tmp>=len(d): return None
    else: return d[tmp]

def left(i, *d):
    tmp = 2*i
    if tmp>=len(d): return None
    else: return d[tmp]
    
def right(i, *d):
    tmp = 2*i+1
    if tmp>=len(d): return None
    else: return d[tmp]

n = int(input())
i = 0
x = map(int, [0] + raw_input().split()) 
for i in range(1, len(x)):
    print "node %d: key = %d," % (i, x[i]),
    tmp = parent(i, *x)
    if tmp != None: print "parent key = %d," %(tmp),
    tmp = left(i, *x)
    if tmp != None: print "left key = %d," %(tmp),
    tmp = right(i, *x)
    if tmp != None: print "right key = %d," %(tmp),
    print ""

Measured memory_bytes: 4264
#include<stdio.h>
int main(){
  long long n,a,b,tmp,ans=0,di;
  scanf("%lld %lld %lld",&n,&a,&b);
  tmp = a+b;
  di = n/tmp;
  ans += a*di;
  n %= tmp;
  if(n<=a){
    ans += n;
  }else{
    ans += a;
  }
  printf("%lld\n",ans);
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    int n;
    cin >> n;
    for (int i=0; i<n; ++i)
    {
        string str;
        cin >> str;
        if(str=="Y")
        {
            cout << "Four" << endl;
            return 0;
        }
    }

    cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 256
num = int(input())
dict = {}
for i in range(num):
  key = input()
  if not key in dict:
    dict[key] = 1
  else:
    dict[key] += 1
max_v = max(dict.values())
keys = [k for k, v in dict.items() if v == max_v]
keys.sort()
for i in range(len(keys)):
  print(keys[i])
    

Measured memory_bytes: 32096
//AtCoder Beginner Contest 088
//B - Card Game for Two

#include <iostream>
#include <algorithm>

using namespace std;

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

    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a, a+n);

    long sum1 = 0;
    long sum2 = 0;
    for(int i=0;i<n;i++){
        if(i%2==0) sum1 += a[i];
        else sum2 += a[i];
    }

    if(n%2==0){
        cout << sum2-sum1 << endl;
    }else{
        cout << sum1-sum2 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#define DEBUG 0
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 7/20/2019, 8:47:01 PM
 * Powered by Visual Studio Code
 */
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using ll = long long;
class mint
{
public:
  static ll MOD;
  ll x;
  mint() : x(0) {}
  mint(ll x) : x(x % MOD) {}
  mint operator-() const { return x ? MOD - x : 0; }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= MOD)
    {
      x -= MOD;
    }
    return *this;
  }
  mint &operator-=(const mint &a) { return *this += -a; }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint &operator/=(const mint &a)
  {
    mint b{a};
    return *this *= b.power(MOD - 2);
  }
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
  const mint power(ll N)
  {
    if (N == 0)
    {
      return 1;
    }
    else if (N % 2 == 1)
    {
      return *this * power(N - 1);
    }
    else
    {
      mint half = power(N / 2);
      return half * half;
    }
  }
};
ll mint::MOD = 1e9 + 7;
istream &operator>>(istream &stream, mint &a) { return stream >> a.x; }
ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; }
class combination
{
public:
  vector<mint> inv, fact, factinv;
  static int MAX_SIZE;
  combination() : inv(MAX_SIZE), fact(MAX_SIZE), factinv(MAX_SIZE)
  {
    inv[1] = 1;
    for (auto i = 2; i < MAX_SIZE; i++)
    {
      inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
    }
    fact[0] = factinv[0] = 1;
    for (auto i = 1; i < MAX_SIZE; i++)
    {
      fact[i] = mint(i) * fact[i - 1];
      factinv[i] = inv[i] * factinv[i - 1];
    }
  }
  mint operator()(int n, int k)
  {
    if (n >= 0 && k >= 0 && n - k >= 0)
    {
      return fact[n] * factinv[k] * factinv[n - k];
    }
    return 0;
  }
};
int combination::MAX_SIZE = 1e6 + 10;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// constexpr double epsilon = 1e-10;
// constexpr ll infty = 1000000000000000LL;
// constexpr int dx[4] = {1, 0, -1, 0};
// constexpr int dy[4] = {0, 1, 0, -1};
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}
void No()
{
  cout << "No" << endl;
  exit(0);
}

int main()
{
  int r;
  cin >> r;
  cout << 3 * r * r << endl;
}

Measured memory_bytes: 256
n, y =  map(int, input().split())
for i in range(n+1):
    for j in range(n+1-i):
        if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
            print(i, j, n - i - j)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 2940
#include <algorithm>
#include <cassert>
#include <iostream>
#include <memory>
#include <numeric>

#include <array>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <ostream>
#include <type_traits>
#include <utility>
#include <chrono>

#ifdef ONLINE_JUDGE
#pragma GCC optimize ("O3")
#pragma GCC target ("avx,avx2")
#endif

using namespace std;

using u64 = uint64_t;
using i64 = int64_t;
using u32 = uint32_t;
using vi = vector<int>;
using vi64 = vector<i64>;

#define seq(i,a,b) for (int i = (a); i < (b); ++i)
#define rev(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define sz(x) (x.size())
#define all(x) x.begin(), x.end()
#define dbg(x) {cerr << #x << ": " << x << endl;}


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

    int n,m; cin >> n >> m;
    vi64 A(n);
    for (auto &x : A) cin >> x;

    vector<pair<i64,i64>> Q(m);
    for (auto &p : Q) {
        cin >> p.second >> p.first;
    }

    sort(all(A));
    sort(all(Q));
    reverse(all(Q));
    
    int i = 0;
    for (auto &p : Q) {
        int c,b;
        tie(c,b) = p;
        while (i < n && c > A[i] && b > 0) {
            --b;
            A[i] = c;
            ++i;
        }
    }

    cout << accumulate(all(A), 0LL) << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <string>

using namespace std;

void solve() {
    string a, b;
    cin >> a >> b;
    cout << b << a << endl;
}

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

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

#define ll long long
#define pb push_back
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    ll n;
    cin >> n;
    vector<ll> div(n+1, 0);
    for(ll i = 1; i<=n; i++) {
        for(ll j = i; j<=n; j+=i) {
            div[j] ++;
        }
    }
    ll ans = 0;
    for(ll i = 1; i<=n; i++) {
        ll curr = i * div[i];
        ans += curr;
    }
    cout << ans << '\n';
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 81340
#include <iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int a[10000001]={0};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    # ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    string s,t;
    int c=0;
    cin>>s>>t;
    for (int i = 0; i < s.length(); ++i)
    {
      /* code */
      if(s[i]!=t[i])
        c++;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll inf=1e10;
const ll maxs = 201;
const ll mod = 1e9+7;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define line cout<<endl;
#define fr(i,b) for(ll i=1;i<=b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

string a,b;

void solve()
{
    ll sa = a.size(),sb = b.size();
    ll dp[sa+1][sb+1];
    memset(dp,0,sizeof dp);
    for(ll i=1;i<=sa;i++)
    {
        for(ll j=1;j<=sb;j++)
        {
            if(b[j-1]==a[i-1])
                dp[i][j] = 1+dp[i-1][j-1];
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    
    /*for(ll i=0;i<=sa;i++)
    {
        for(ll j=0;j<=sb;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;    
    }*/
    
    
    ll i=sa,j=sb;
    string ans="";
    while(i>0&&j>0)
    {
        if(dp[i][j]>dp[i][j-1]&&dp[i][j]>dp[i-1][j])
        {
            ans += a[i-1]; // or  b[j-1];
            i--;j--;
        }    
        else if(dp[i-1][j]>dp[i][j-1])
            i--;
        else 
            j--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    
}

int main()
{
    fastio();
     ll t=1;
     // cin>>t;
     while(t--){
        cin>>a>>b;
        solve();          
     }
    return 0;
}



Measured memory_bytes: 70656
#辺の重み(変化量)が0である場合は01DFSって特別なやつ
#0の場合はそこでBFSできる
import sys
from collections import deque
sys.setrecursionlimit(10**7)
input=sys.stdin.readline
h,w=map(int,input().split())
c=[int(i)-1 for i in input().split()]
d=[int(i)-1 for i in input().split()]
s=[input() for i in range(h)]
inf=100000000
dp=[[-1 if s[i][j]=="#" else inf for j in range(w)] for i in range(h)]
dp[c[0]][c[1]]=0
now=deque([[c[0],c[1]]])
def bfs():
    global h,w,s,dp,now
    while len(now):
        i,j=now.popleft()
        for k,l in [[i-1,j],[i+1,j],[i,j-1],[i,j+1]]:
            if 0<=k<h and 0<=l<w:
                if dp[k][l]!=-1:
                    if dp[k][l]>dp[i][j]:
                        dp[k][l]=dp[i][j]
                        now.appendleft([k,l])
        for k in range(i-2,i+3):
            for l in range(j-2,j+3):
                if 0<=k<h and 0<=l<w:
                    if dp[k][l]!=-1:
                        if dp[k][l]>dp[i][j]+1:
                            dp[k][l]=dp[i][j]+1
                            now.append([k,l])
bfs()
print(dp[d[0]][d[1]] if dp[d[0]][d[1]]!=inf else -1)

Measured memory_bytes: 119232
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,k,l = 0,r = 0,i,j,ans = 0;cin >> n >> k;
  long long a = k,b = n-k;
  for(i=0;i<k;i++) l = (l+i)%1000000007;
  for(i=n;i>n-k;i--) r = (r+i)%1000000007;
  while(a-2 != n){
    ans = (ans+(r-l+1))%1000000007;
    l = (l+a)%1000000007;r = (r+b)%1000000007;
    a++;b--;
  }
  if(ans<0) ans += 1000000007; 
  cout << ans << endl;
}
    
  

Measured memory_bytes: 3624
H, W = gets.split.map(&:to_i)
S = ['.' * (W + 2)] + readlines.map{|l| '.' + l.chomp + '.'} + ['.' * (W + 2)]

(1 .. H).each do |i|
  (1 .. W).each do |j|
    next if S[i][j] == '.'
    (puts 'No'; exit) if [S[i-1][j], S[i+1][j], S[i][j-1], S[i][j+1]].all?{|s| s == '.'}
  end
end
puts 'Yes'

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
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;}

template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;

int main(){
    int n;
    cin>>n;
    vector<int> a(n,0);
    rep(i,n)cin>>a[i];
    int res=gcd(a[0],a[1]);
    rep(i,n-2){
        res=gcd(res,a[i+2]);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 640
n = int(input())
li = [list(map(int,input().split())) for _ in range(n)]

if n == 1:
    print(1)
    exit()
li2 = [(x[0]-y[0],x[1]-y[1]) for x in li for y in li]
data = list(set(li2)) #かぶりを消すような作業や、カウントする前はsetがよい
data.remove((0,0))
data2 = tuple(data) #forなどでlistの中身をたくさん参照する場合はtupleがよい
qty = list(map(lambda x: li2.count(x),data2))

print(n-max(qty))


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

int main() {
  int N, X;
  cin >> N >> X;
  
  vector<int> m(N);
  for (int i = 0; i < N; i++) cin >> m.at(i);

  int amount = X;
  int count = N;
  for (int i = 0; i < N; i++) amount -= m.at(i);
  
  sort(m.begin(), m.end());
  
  for (int i = 0; i < N; i++) {
    if (amount - m.at(i) < 0) {
      break;
    }
    else {
      int s = amount / m.at(i);
      count += s;
      amount %= m.at(i); 
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3632
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

if a%10==0:
  p=10
else:
  p=a%10
  a=a-p+10
  
if b%10==0:
  q=10
else:
  q=b%10
  b=b-q+10
  
if c%10==0:
  r=10
else:
  r=c%10
  c=c-r+10
  
if d%10==0:
  s=10
else:
  s=d%10
  d=d-s+10
  
if e%10==0:
  t=10
else:
  t=e%10
  e=e-t+10
  
x=a+b+c+d+e
y=min(p,q,r,s,t)
print(x+y-10)

Measured memory_bytes: 3064
#include<cstdio>
const int N=2005;
int l[N][N],r[N][N],h[N][N],n,m,ans,mp[N][N],a[N][N];
char s[N];
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int main(){
//	freopen("ex.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%s",s+1);
		for(int j=1;j<=m;++j) mp[i][j]=(s[j]=='#');
	}
	for(int i=1;i<n;++i) for(int j=2;j<=m;++j) if((mp[i][j]^mp[i+1][j])==(mp[i][j-1]^mp[i+1][j-1])) a[i+1][j]=1;n++;
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j){
		if(a[i][j]==1) h[i][j]=h[i-1][j]+1,l[i][j]=l[i][j-1]+1;
		if(a[i][m-j+1]==1) r[i][m-j+1]=r[i][m-j+2]+1;
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			if(h[i][j]>1){
				l[i][j]=min(l[i][j],l[i-1][j]);
				r[i][j]=min(r[i][j],r[i-1][j]);
			}
			ans=max(ans,(l[i][j]+r[i][j])*(h[i][j]+1));
		}
	}
	printf("%d\n",max(ans,max(n-1,m)));
	return 0;
} 

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

#define INF 1234567890
#define ll long long
#define MOD 998244353

int N, S;
int A[3030];

int main()
{
	scanf("%d %d", &N, &S);
	for(int i=1; i<=N; i++)
		scanf("%d", &A[i]);

	vector<ll> res(S+1), sum(S+1);
	sum[0]++;
	if (A[N] <= S) sum[A[N]]++;
	for(int j=0; j<=S; j++)
	{
		res[j] += sum[j];
		res[j] %= MOD;
	}
	for(int i=N-1; i>=1; i--)
	{
		sum[0]++;
		for(int j=S-A[i]; j>=0; j--)
		{
			sum[j+A[i]] += sum[j];
			sum[j+A[i]] %= MOD;
		}
		for(int j=0; j<=S; j++)
		{
			res[j] += sum[j];
			res[j] %= MOD;
		}
	}
	printf("%lld", res[S]);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long long n, i, max, min, sum;
    i = 0;
    max = -1000000;
    min = 1000000;
    sum = 0;
    cin >> n;
    
    while(i < n){
        int a;
        cin >> a;
        if(a > max){
            max = a;
        }
        if(a < min){
            min = a;
        }
        sum += a;
        i += 1;
    }
    
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


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

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main(){
	int n , q;
	cin >> n >> q;
	UnionFind uf(n);
	for(int i = 0 ; i < q ; i++){
		int t , u , v;
		cin >> t >> u >> v;
		if(t==0){
			uf.unite(u,v);
		}
		else{
			if(uf.same(u,v))
				cout<<"1\n";
			else
				cout<<"0\n";
			}
	}
}


Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define cin_fit() cin.tie(nullptr);ios::sync_with_stdio(false)
#define rep(i, N) for(int i=0; i<(N); i++)
#define reps(i, N) for(int i=1; i<=(N); i++)
#define rrep(i, N) for(int i=(int)(N)-1; i>=0; i--)
#define rreps(i, N) for(int i=(int)(N); i>=1; i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using V = vector<ll>;
using P = pair<ll, ll>;
constexpr int inf = 1e9;
constexpr int mod = 1e9+7;
ll gcd(ll a, ll b) { return b? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}

ll n, k;
string s;

int main() {
    cin_fit();
    cin >> n >> k >> s;
    k--;
    transform(s.begin()+k, s.begin()+k+1, s.begin()+k, ::tolower);
    cout << s << endl;
    return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  int N;
  cin >> N;
  vector<int> A(N), B;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    for (int j = 0; j < A[i]; j++) {
      B.push_back(i);
    }
  }

  vector<vector<int>> C(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      C[i][j] = B[i * W + j];
    }
    if (i % 2 == 1) {
      reverse(C[i].begin(), C[i].end());
    }
    for (int j = 0; j < W; j++) {
      cout << C[i][j] + 1 << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define quickcin ios_base::sync_with_stdio(false);
const int mod=1e9+7;
const int inf=1039074182;
const ll llinf=1LL*inf*inf;
using namespace std;
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
template <typename T1,typename T2> inline void chadd(T1 &x,T2 b) {x+=b;if(x>=mod) x-=mod;};
template <typename T1,typename T2> inline void chmod(T1 &x,T2 b) {x%=b,x+=b;if(x>=b) x-=b;}
int a[200005];
int n;

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n;
	int s=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		s^=a[i];
	}
	for(int i=0;i<n;i++)
	{
		printf("%d ",a[i]^s);
	}
	return 0;
}

Measured memory_bytes: 4536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n>=400 && n<=599)
        cout<<"8";
    else if(n>=600 && n<=799)
        cout<<"7";
    else if(n>=800 && n<=999)
        cout<<"6";
    else if(n>=1000 && n<=1199)
        cout<<"5";
    else if(n>=1200 && n<=1399)
        cout<<"4";
    else if(n>=1400 && n<=1599)
        cout<<"3";
    else if(n>=1600 && n<=1799)
        cout<<"2";
    else if(n>=1800 && n<=1999)
        cout<<"1";
    return 0;
}


Measured memory_bytes: 3576
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    int sum = 0;
    cin >> a >> b;
    if (a >= 2)
    {
        sum = sum + (a *( a - 1)) / 2;
    }
    if (b >= 2)
    {
        sum = sum + (b * (b - 1)) / 2;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# 1つ目の入力
num = int(input())

# スペース区切りの整数の入力
num_list = list(map(int,input().split()))

def judge(num_list, num):
    if num == 1:
        return('Yes')

    decrease = False
    for i in range(0,len(num_list)):
        if i + 1 == num:  # 終わりなので、何もしない
            return('Yes')  # 最後までOKだったので、Yesをリターン

        if num_list[i] == num_list[i+1]:
            pass
        elif num_list[i] < num_list[i+1]:
            decrease = False
        elif num_list[i] - 1 <= num_list[i+1]:
            if decrease:
                return('No')
            else:
                decrease = True
        else:
            return('No')
        '''
        for j in range(i+1,len(num_list)):
          if num_list[i] -1 <= num_list[j]:
            if i+1 == num-1:
                return('Yes')
          else:
            return('No')
        '''


print(judge(num_list, num))

Measured memory_bytes: 14396
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h[100000],z,x,c,i,j;
	scanf("%d",&a);
	for(i=1;i<=a;i++){
		scanf("%d %d %d %d",&s,&d,&f,&g);
		h[i]=s*f+d*g;
		z=f;
		x=g;
		if(z<5){
			z=5;
		}
		if(x<2){
			x=2;
		}
		c=(s*z+d*x)*0.8;
		if(h[i]>c){
			h[i]=c;
		}
	}
	for(i=1;i<=a;i++){
		printf("%d\n",h[i]);
	}
	return 0;
}

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

struct Graph{
	
	vector<char> seen;
	vector<vector<int>> e;
	vector<int> time1,time2; 
	Graph(int n) : seen(n),e(n),time1(n),time2(n){}
	
	void dfs(int v, int &t){
		t++;
		time1.at(v) = t;
		seen.at(v) = 1;
		for(auto nv:e.at(v)) {
			if(seen.at(nv)==1) continue;
			dfs(nv,t);
		}
		t++;
		time2.at(v) = t;
		return;
	}
	
};

int main() {
	
	int n;
	cin >> n;
	Graph graph(n);
	for(int i=0; i<n; i++){
		int u,k;
		cin >> u >> k;
		for(int j=0; j<k; j++){
			int v;
			cin >> v;
			v--;
			graph.e.at(i).push_back(v);
		}
	}
	
	int t={};
	for(int i=0; i<n; i++){
		if(graph.seen.at(i)!=1) graph.dfs(i,t);
	}
	
	for(int i=0; i<n; i++){
		cout << i+1 << ' ' << graph.time1.at(i) << ' ' << graph.time2.at(i) << endl;
	}
	
	
}


Measured memory_bytes: 3152
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
signed main(){
  double a,b;
  cin>>a>>b;
  vector<int> c(a);
  rep(i,a)
    cin>>c[i];
  cout<<ceil((a-1)/(b-1))<<endl;
}

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

int main() {
	int H, W;
	while(1){
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		
		for ( int i = 1; i <= H; i++){

			for (int j = 1; j <= W; j++){
				if ( i == 1 || i == H || j == 1 || j == W) cout << "#";
				else cout << ".";
				}
				cout << "\n";
			}
			cout << endl;
	}
		
	return 0;
}

Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {// AtCoderは必ずMainクラスで提出する
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();
		if(R < 1200) System.out.println("ABC");
		else if(R < 2800)System.out.println("ARC");
		else System.out.println("AGC");
	}
}


Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b){
            System.out.println("a < b");
        } else if(a>b){
            System.out.println("a > b");
        } else{
            System.out.println("a == b");
        }
    sc.close();
    }
}


Measured memory_bytes: 26224
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		HashSet<Integer> set = new HashSet<>();
		for (int i = 0; i < n; i++) {
		    set.add(sc.nextInt());
		}
		int min = Integer.MAX_VALUE;
		int minvalue = 0;
		for (int i = x - 100; i <= x + 100; i++) {
		    if (!set.contains(i)) {
		        if (min > Math.abs(x - i)) {
		            min = Math.abs(x - i);
		            minvalue = i;
		        }
		    }
		}
	    System.out.println(minvalue);
	}
}


Measured memory_bytes: 35744
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
int n,m,a[1005],b[1005];
bool check()
{
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        if(a[i]==a[j]) return false;
    for(int i=1;i<=m;i++)
        for(int j=i+1;j<=m;j++)
        if(b[i]==b[j]) return false;
    return true;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=m;i++) scanf("%d",&b[i]);
    sort(a+1,a+1+n);
    sort(b+1,b+1+m);
    if(!check()) printf("0\n");
    else
    {
        a[n+1]=n+1;
        b[m+1]=m+1;
        int l[2]={0,0};
        ll ans=1;
        for(int i=1;i<=n*m;i++)
        {
            while(l[0]<=n&&a[l[0]]<i) l[0]++;
            while(l[1]<=m&&b[l[1]]<i) l[1]++;
            ll d=0;
            if(a[l[0]]==i&&b[l[1]]==i) d=1;
            else if(a[l[0]]==i) d=m-l[1]+1;
            else if(b[l[1]]==i) d=n-l[0]+1;
            else d=(m-l[1]+1)*(n-l[0]+1)-(n*m-i);
            ans=ans*d%mod;
        }
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second 

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

constexpr int ms = 1e5 + 13;

long long ans[ms];
// End of template code!
int main() 
{
    buff();
    long long n, k;
    cin >> n >> k;
    long long sum = 0;
    // Fixo um x, quero saber quantos vetores tem gcd exatamente == x
    for(ll x = k; x >= 1ll; --x) {
        // quero saber quantos multiplos de x tem de [1, ..., k]
        long long cand = (k / x);
        // todos os elementos nas posicoes de [0, ..., n] precisam ser algum
        // dos candidatos
        long long contribution = pow_mod(cand, n);
        // so que essa contribuicao inclui gente com gcd's mais altos
        // exemplo x = 4,
        // vetor = [8, 8, 8, ..., 8]..
        // Esse vetor so tem multiplos de 4, mas o gcd de verdade eh 8.
        // Por isso precisamos eliminar alguns casos dessa contribuicao
        for(ll mul = 2; mul * x <= k; ++mul) {
            contribution = (contribution + MOD - ans[(mul * x)]) % MOD; 
        }
        ans[x] = contribution;
        long long inc = (ans[x] * x) % MOD;
        sum = (sum + inc) % MOD;
    }
    cout << sum << '\n';
    return 0;
}



Measured memory_bytes: 4412
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=2e5;
/*
int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
*/
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int n,m; 
char s[N],t[N];

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
#endif
	scanf("%d%d",&n,&m); 
	scanf("%s%s",s,t); 
	ll g=gcd(n,m);
	for(ll i=0,j=0;i<n&&j<m;i+=n/g,j+=m/g){
		if(s[i]!=t[j]){ puts("-1"); return 0; } 
	}
	printf("%lld\n",n/g*m);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <list>
#include <map>

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

using namespace std;

int MAX = 100000;

int main(void){

  //iが素数かどうか
  bool flag[MAX+1];
  rep(i, MAX+1)
    flag[i] = true;

  //素数でない数のフラグを下ろす
  for(int n=2; n<=MAX; n++)
    if(flag[n] )
      for(int m=n+n; m<=MAX; m+=n)
	flag[m] = false;

  //n以下の数字の中に「2017に似た数」がいくつあるか
  int count[MAX+1];
  rep(i, MAX+1)
    count[i] = 0;

  for(int n=3; n<=MAX; n+=2)
    //「2017に似た数」判定
    if(flag[n] && flag[(n+1)/2])
      count[n]++;

  //累積和
  for(int i=3; i<=MAX; i++)
    count[i] = count[i]+count[i-1];

  //入力
  int Q;
  cin >> Q;

  int l, r;
  rep(i, Q){
    cin >> l >> r;
    //累積和を利用したカウント
    cout << count[r] - count[l-1] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 4100
from itertools import accumulate

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

ans = 0
acc = list(accumulate(a))
for i in range(n - 1):
    ans += a[i] * (acc[-1] - acc[i])
    ans %= mod
print(ans)


Measured memory_bytes: 101912
import java.util.*;

class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    String s1=sc.next();
     s1=s1.substring(0,s1.length()-1);
//System.out.println("SubsString is::"+s1);
    if(s1.equals(s))
      System.out.println("Yes");
    else
      System.out.println("No");
    
  }
}  

Measured memory_bytes: 35720
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
 
int main(){
    ll x, y; cin >> x >> y;
    ll a = 0;
    if(x == 1){a += 300000;}
    else if(x == 2){a += 200000;}
    else if(x == 3){a += 100000;}
    if(y == 1){a += 300000;}
    else if(y == 2){a += 200000;}
    else if(y == 3){a += 100000;}
    if(x == 1&&y == 1){
        a += 400000;
    }
    prt(a);
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n;
  int data[100];
  int i, j;
  int temp;
  int count;
  while(1) {
    scanf("%d", &n);
    if(n == 0) break;
    for(i = 0; i < n; i++) {
      scanf("%d", &data[i]);
    }
    count = 0;
    for(i = 0; i < n; i++) {
      for(j = 0; j < n-i-1; j++) {
	if(data[j] > data[j+1]) {
	  temp = data[j];
	  data[j] = data[j+1];
	  data[j+1] = temp;
	  count++;
	}
      }
    }
    printf("%d\n", count);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
const long double EPS = 1e-14;
const int maxn = 100500;
const int mod = 1e9 + 7;


signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector < int > a(n);
    for(auto &x : a) cin >> x;
    for(int i = 1 ; i < n ; ++i) a[i] += a[i - 1];
    int ans = 3e18;
    for(int mid = 1 ; mid < n - 1 ; ++mid){
        int smL = a[mid];
        int smR = a.back() - a[mid];
        int idxL = 0, idxR = n - 2;
        int lo = 0, hi = mid - 1;
        while(lo <= hi){
            int md = (lo + hi) >> 1;
            if(a[md] <= smL / 2) lo = md + 1;
            else hi = md - 1;
        }
        if(lo) idxL = lo - 1;
        lo = mid + 1, hi = n - 2;
        while(lo <= hi){
            int md = (lo + hi) >> 1;
            if(a[md] - a[mid] <= smR / 2) lo = md + 1;
            else hi = md - 1;
        }
        if(lo) idxR = lo - 1;
        for(int midL = max(0LL, idxL - 2) ; midL < min(mid, idxL + 2) ; ++midL)
            for(int midR = max(mid + 1, idxR - 2) ; midR < min(n - 1, idxR + 2); ++midR){
                vector < int > sms;
                sms.push_back(a[midL]);
                sms.push_back(a[mid] - a[midL]);
                sms.push_back(a[midR] - a[mid]);
                sms.push_back(a.back() - a[midR]);
                sort(all(sms));
                ans = min(ans, sms.back() - sms[0]);
            }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define MaxN 1000010
//#define MOD 998244353
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define endl '\n'
#define LL long long
#define PII pair<int,int>
#define rint register int 
#define ULL unsigned long long
const int MOD=1e9+7;
//int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
//int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
template<class T> inline void read(T& x){
    x=0;int f=0;char ch=getchar();
    while( !isdigit(ch) ) f|=( ch == '-' ) , ch=getchar();
    while( isdigit(ch) )  x = ( x<<1 ) + ( x<<3 ) + ( ch^48 ) , ch=getchar();
    x = f ? -x : x;
}
template<class T> inline void print(T x){
	if ( x < 0 ) { putchar('-'); x = -x; }
	if ( x >= 10 ) print( x / 10 );
	putchar(x % 10 + '0');
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int n; cin>>n;
    string str; cin>>str;
    int ans=0,left=0,right=str.length()-1;
    while( left <= right ){
        while( str[left] !='W' && left < n ) left++;
        while( str[right] !='R' && right >= 0 ) right--;
        if( left > right ) break;
        if( str[left] =='W' && str[right]=='R' ){
            ans++;
            swap(str[left],str[right]);
        //    cout<<str<<endl;
            left++,right--;
        }
    //    cout<<str<<endl;
    }
    cout<<ans;
	return 0; 
}

Measured memory_bytes: 3720
n,m=map(int,input().split())
a=[-1]*n

flag=True
for i in range(m):
    s,c=map(int,input().split())
    if a[s-1]!=c and a[s-1]<0:
        a[s-1]=c
    elif a[s-1]!=c and a[s-1]>=0:
        flag=False
        print(-1)
        break
if flag:
    for i in range(1,n):
        if a[i]==-1:
            a[i]=0
    if a[0]==-1 and n==1:
        a[0]=0
    elif a[0]==-1 and n>1:
        a[0]=1
    elif a[0]==0 and n>1:
        print(-1)
        flag=False

ans=''
if flag:
    for i in range(n):
        ans+=str(a[i])
    print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<double> vec(n);
	rep(i, 0, n - 1)cin >> vec[i];
	sort(all(vec));
	double ans = vec[0];
	rep(i, 1, n - 1)
	{
		ans = (ans + vec[i]) / 2;
	}
	printf("%.6f", ans);
}

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

using namespace std;

int main(){
    string s, t;
    cin >> s >> t;
    bool flag = false;
    if(s.size()+1 == t.size()){
        t.pop_back();
        if(s == t) flag = true;
    }

    cout << (flag ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,n;
	cin>>k>>n;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	int total = k;
	int mn = total;
	for(int i=1; i<n; i++){
		mn = min(mn,total-(arr[i]-arr[i-1]));
	}
	mn = min(mn,total-(k-arr[n-1])-arr[0]);
	cout<<mn;
}

Measured memory_bytes: 4056
n, w = gets.chomp.split.map(&:to_i)
dp = Array.new(n + 1) { Hash.new(0) }
dp[0][w] = 0

n.times do |t|
  wi, vi = gets.chomp.split.map(&:to_i)
  prev = dp[t].keys
  prev.each do |k|
    next if k < 0
    dp[t + 1][k] = [dp[t][k], dp[t + 1][k]].max
    if k >= wi
      dp[t + 1][k - wi] = [dp[t + 1][k - wi], dp[t][k] + vi].max
    end
  end
end
puts dp[n].values.max

Measured memory_bytes: 18324
#include<iostream>
using namespace std;
int main(){
	int a;
	int b;
	int ata;
	int bta;
	scanf("%d",&a);
	scanf("%d",&ata);
	scanf("%d",&b);
	scanf("%d",&bta);
	int timesa=b/ata;
	if(b%ata!=0)timesa+=1;
	int timesb=a/bta;
	if(a%bta!=0)timesb+=1;
	if(timesa<=timesb)printf("Yes");
	else printf("No");
	return 0; 
}


Measured memory_bytes: 3728