akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		int cnt = 0;
		for(int i = 0; i < N.length(); i++) {
			if(i % 2 == 0) {
				if(N.charAt(i) == 'R' || N.charAt(i) == 'U' || N.charAt(i) == 'D') {
					cnt++;
				}
			}else if(i % 2 == 1) {
				if(N.charAt(i) == 'L' || N.charAt(i) == 'U' || N.charAt(i) == 'D') {
					cnt++;
				}
			}
		}
		
		if(cnt == N.length()) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}		
		sc.close();
	}
}


Measured memory_bytes: 23252
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;
  string s;
  cin >> s;

  vector<ll> e(n + 1,0),w(n + 1,0);

  // east →
  rep(i,n)
  {
    e[i+1] = e[i] + (s[i] == 'E' ? 1 : 0);
  }

  // west <-
  rep(i,n)
  {
    w[i+1] = w[i] + (s[i] == 'W' ? 1 : 0);
  }

  ll ans = LLONG_MAX;

  rep(i,n)
  {
    ans = min(ans,w[i] + e[n] - e[i+1]);
  } 

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 5380
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int INF=1000005;
const int MOD=1e9+7;
const int N=1e6+7;
int n,m;
struct Q{
    int ql,qr,id,sum;
}q[N];
int a[N],b[N],cnt[N];
int last[N],ans[N];
bool cmp(Q x,Q y)
{
    if(x.qr==y.qr) return x.ql<y.ql;
    return x.qr<y.qr;
}
bool cmp_id(Q x,Q y)
{
    return x.id<y.id;
}
int lowbit(int x)
{
    return x&(-x);
}
void add(int x,int k)
{
    for(int i=x;i<=n;i+=lowbit(i))
    b[i]+=k;
}
int query(int x)
{
    int res=0;
    for(int i=x;i;i-=lowbit(i))
        res+=b[i];
    return res;
}
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%d",&q[i].ql,&q[i].qr),q[i].id=i;
    sort(q+1,q+m+1,cmp);
    int nxt=1;
    for(int i=1;i<=m;++i)
    {
        for(int j=nxt;j<=q[i].qr;++j)
        {
            if(last[a[j]])
                add(last[a[j]],-1);
            add(j,1);
            last[a[j]]=j;
        }
        nxt=q[i].qr+1;
        ans[q[i].id]=query(q[i].qr)-query(q[i].ql-1);
    }
    for(int i=1;i<=m;++i)
        printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 19456
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    string s;
    cin >> s;
    ll res = 0;
    REP(i, s.size() - 1){
        if(s[i + 1] != s[i]) res++;
    }
    cout << res << endl;
    return 0;
}

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

int main(){
	while(1){
		int s1,s2;
		int maxc=0;
		int max=0;
		for(int i=0;i<5;i++){
			cin >> s1 >> s2;
			if(!s1&&!s2)return 0;
			if(s1+s2>max){
				max = s1 + s2;
				maxc = 'A'+i;
			}
		}
		cout << (char)maxc << " " << max << endl;
	}
}

Measured memory_bytes: 0
import fractions
def main():
    N = int(input())
    CLK = [int(input()) for i in range(N)]
    gcd = CLK[0]
    lcm = CLK[0]

    for i in range(1, N):
        gcd = fractions.gcd(gcd, CLK[i])
        lcm = (lcm * CLK[i])//gcd
        gcd = lcm

    print(int(lcm))

if __name__ == "__main__":
    main()

Measured memory_bytes: 5048
a = map(int, raw_input().split(" "))
A = a[0]
a[1]
a[2]
b = []

while True:
    B = A % a[1]
    if A >= a[1]:
        if (B == a[2]):
            print "YES"
            quit()

        if B in b:
            print "NO"
            quit()
        else:
            b.append(B)
    A += a[0]


Measured memory_bytes: 2568
N = gets.to_i
a = gets.split(" ").map(&:to_i)
a.sort!
max = 0
j = 0
a.size.times do |i|
  while j < a.size && a[j] <= a[i] + 2 do
    max = [max, j-i].max
    j += 1
  end
end
puts max+1


Measured memory_bytes: 12272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1005;
const ll INF=1LL<<60;
const double eps=1e-9;
int lim;
int DFS(double rem,int maxi,int cnt,int seki){
    if(rem<-eps) return 0;
    if(rem<eps) return 1;
    if(cnt==0) return 0;
    ll ans=0;
    for(int i=1;i<=maxi;i++){
        if(seki*i>lim) break;
        ans+=DFS(rem-1.0/i,i,cnt-1,seki*i);
    }
    
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        double p,q;cin>>p>>q;
        int a,n;cin>>a>>n;
        lim=a;
        if(a+n==0) break;
        
        cout<<DFS(p/q,a,n,1)<<endl;
    }
}





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

#define ll unsigned long long int
#define ld long double
#define mod 1000000007LL
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define endl '\n'
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mp make_pair
#define pb(x) push_back(x)
#define fo(i, a, n) for (i = (a); i < (n); i++)
#define foe(i, a, n) for (i = (a); i <= (n); i++)
// clang-format off
#define vin(a) for (ll i = 0; i < sz(a); i++) { cin >> a[i]; } 
#define vout(a) for (auto x : a) { cout << x << " "; }
#define sws                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0)
// clang-format on
#define pd(x) cout << x
#define sd(x) cin >> x
#define nl cout << endl
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define foreach(i, a)                                                          \
  for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define sz(a) (int)((a).size())
// int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
void solve() {
  ll m = 1, n;
  ll i, j;
  cin >> n;

  ll maxval = pow(10LL, 18);

  vll a(n);
  vin(a);

  fo(i, 0, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return;
    }
  }

  fo(i, 0, n) {
    m *= a[i];
    ll nextmax = maxval / m;

    if (i == n - 1)
      continue;

    if (a[i + 1] > nextmax) {
      cout << -1 << endl;
      return;
    }
  }

  cout << m << endl;
}

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

Measured memory_bytes: 3992
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
inline int read()
{
	int num=0, w=0;
	char ch=0;
	while (!isdigit(ch))
	{
		w|=ch=='-';
		ch = getchar();
	}
	while (isdigit(ch))
	{
		num = (num<<3) + (num<<1) + (ch^48);
		ch = getchar();
	}
	return w? -num: num;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=2e6+10;
int a[N];
int b[N];
void solve()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i];
	for(int i=1;i<=n-2;i++)
	{
		if(a[i]==b[i]&&b[i+1]==a[i+1]&&a[i+2]==b[i+2])
		{
			cout<<"Yes"<<endl;
			return ;
		}
	 } 
	 cout<<"No"<<endl;
}
signed main()
{
	int t=1;
	while(t--)
		solve();
	return 0;
}



Measured memory_bytes: 3636
#include <cstdio>
int main(){
int a,b,c,d,i;scanf("%d%d%d",&a,&b,&c);i=c-60;d=a+b;
while((i+=60)<3600)
if(0<=i%d&&i%d<=a)
break;
printf("%d\n",i>3599?-1:i);return 0;}

Measured memory_bytes: 1028
s = input()
n = int(input())
for i in range(n):
    order, a, b, *c = input().split()
    a = int(a)
    b = int(b)
    if order == 'replace':
        s = s[:a] + c[0] + s[b+1:]
    elif order[0] == 'r':
        s = s[:a] + s[::-1][len(s)-b-1:len(s)-a]+ s[b+1:]
    else:
        print(s[a:b+1])


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

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

	int n,m,t;
	int sum = 0;
	cin >> n >> m;

	for(int i=0;i<m;i++)
	{
		cin >> t;
		sum += t;
	}

	if(sum > n)
	{
		cout << -1 << '\n';
	}
	else
	{
		cout << n - sum << '\n';
	}
	
	return 0;
}

Measured memory_bytes: 3696
#include <iostream>

using namespace std;

int main()
{
	int a,b,c,i,j=0;;
	cin >> a >> b >> c;
	for(i=a;i<=b;i++)
	{
	    if(c%i==0) 
            j++;
	}
	cout << j << endl;
	return 0;
}



Measured memory_bytes: 3116
#define M 3009
#include <stdio.h>
char* F(char *b,int n,FILE *f){char *r=fgets(b,n,f);if(!r)return NULL;b[strlen(b)-1]=0;return r;}
#define max(a,b) ((a)>(b)?(a):(b))
int lcs[M][M];
char a[M],b[M],l[M];
backtrack(i,j){
	if(i==0||j==0);
	else if(a[i]==b[j])backtrack(i-1,j-1),putchar(a[i]);
	else if(lcs[i][j-1]>lcs[i-1][j])backtrack(i,j-1);
	else backtrack(i-1,j);
}
main(int argc, char **argv){
  if(argc>1)freopen(argv[1],"rb",stdin);
  int i,j,_a,_b;
  strcpy(a,"*"),strcpy(b,"*");
  F(l,M,stdin);strcat(a,l);
  F(l,M,stdin);strcat(b,l);
  _a=strlen(a+1);_b=strlen(b+1);
  for(i=1;i<=_a;i++)
    for(j=1;j<=_b;j++){
#if 1
      if(a[i]==b[j])lcs[i][j]=lcs[i-1][j-1]+1;
      else lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
#else
      lcs[i][j]=max(max(lcs[i-1][j],lcs[i][j-1]),lcs[i-1][j-1]+(a[i]==b[j]));
#endif
    }
  backtrack(_a,_b);puts("");
}

Measured memory_bytes: 35456
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, ma, mb;
int a[44], b[44], c[44];

int dp[44][440][440];

int solve() {
    for (int i = 0; i < 44; i++)
        for (int j = 0; j < 440; j++)
            fill_n(dp[i][j], 440, inf);

    dp[0][0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 440; j++)
            for (int k = 0; k < 440; k++)
                dp[i][j][k] = dp[i-1][j][k];
        for (int j = 0; j <= 400; j++) {
            for (int k = 0; k <= 400; k++) {
                dp[i][j+a[i-1]][k+b[i-1]] = min(dp[i][j+a[i-1]][k+b[i-1]], dp[i-1][j][k] + c[i-1]);
            }
        }
    }

    int res = inf;
    int p = 1;
    while (ma*p < 440 && mb*p < 440) {
        if (dp[n][ma*p][mb*p] < res) {
            res = dp[n][ma*p][mb*p];
        }
        p++;
    }
    return (res < inf ? res : -1);
}

void input() {
    cin >> n >> ma >> mb;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 33536
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int temp=n;
    int lastdigit;
    int digits=0;
    while(n!=0){
        lastdigit=n%10;
        n/=10;
        digits++;
    }
    int result=0;
    while(digits){
        result*=10;
        digits--;
        result+=lastdigit;
    }
    if(result>=temp){
        cout<<result;
    }
    else
    {
        cout<<(result+111);
    }
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
ll N;
ll d[2000010];
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N){
        cin>>d[i];
    }

    REP(i,1,N){
        d[i] += d[i-1];
    }

    ll ans = LLINF;
    REP(i,0,N-1){
        ans = min(ans, abs(d[i] - (d[N-1] - d[i])));
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1792
//code by lynmisakura.wish to be accepted!
/*************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
void getZarr(string str, int Z[]);

bool search(string text, string pattern)
{

	string concat = pattern + "$" + text;
	int l = concat.length();
	int c = 0;
	int Z[l];
	getZarr(concat, Z);
	
	for (int i = 0; i < l; ++i)
	{
		if (Z[i] == pattern.length()) {
			return true;
		}
	}
	return false;
}

void getZarr(string str, int Z[])
{
	int n = str.length();
	int L, R, k;

	L = R = 0;
	for (int i = 1; i < n; ++i)
	{
		if (i > R)
		{
			L = R = i;
			while (R < n && str[R - L] == str[R])
				R++;
			Z[i] = R - L;
			R--;
		}
		else
		{
			k = i - L;

			if (Z[k] < R - i + 1)
				Z[i] = Z[k];
			else
			{
				L = i;
				while (R < n && str[R - L] == str[R])
					R++;
				Z[i] = R - L;
				R--;
			}
		}
	}
}
int main(void) {
	int n; cin >> n; string s; cin >> s;
	int l = 0, r = n;

	while (r - l > 1) {
		int m = (l + r) / 2;

		bool check = false;
		for (int i = 0; i < n - m; i++) {
			//i文字目からm文字
			string p = s.substr(i, m);//cout << p << endl;
			string r;
			for (int j = i; j < i+m; j++)
			{
				r += (char)s[j];
			}
			string q;
			for (int j = i + m; j < n; j++) {
				q += (char)s[j];
			}
			//cout << p << " " << q << endl;
			if (search(q, r)) {
				check = true; break;
			}
		}
		if (check) {
			l = m;
		}
		else {
			r = m;
		}
	}
	cout << l << endl;
}
//kotti tadasii


Measured memory_bytes: 888
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import string
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


def bisect_left_callable(fn, x, lo, hi):
    """
    lo から hi-1 のうち、fn の結果が x 以上となる、最も左の値
    bisect.bisect_left と同じ
    https://docs.python.org/ja/3/library/bisect.html
    :param callable fn:
    :param x:
    :param int lo: 最小値
    :param int hi: 最大値 + 1
    :return: lo <= ret <= hi
    """
    while lo < hi:
        mid = (lo + hi) // 2
        if fn(mid) < x:
            lo = mid + 1
        else:
            hi = mid
    return lo


N, A, B = list(map(int, sys.stdin.readline().split()))
H = [int(sys.stdin.readline()) for _ in range(N)]
H = np.array(H)


def can_clear(count):
    # 倒せるなら 1、倒せないなら 0
    # 爆発の回数を決めたときにそれぞれ何回中心に選べばいいか
    center_counts = np.maximum(0, np.ceil((H - count * B) / (A - B)))
    return int(center_counts.sum() <= count)


cnt = bisect_left_callable(can_clear, 1, lo=1, hi=10 ** 10)
print(cnt)


Measured memory_bytes: 18368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
struct side{
	int from,to,next;
}a[200010];
int n,m,h[100010],head[100010]={},cnt=0,ans=0;
bool vis[100010]={};
void add(int x,int y){
	++cnt;
	a[cnt].from=x;
	a[cnt].to=y;
	a[cnt].next=head[x];
	head[x]=cnt;
}


int main(){
	cin>>n>>m;
	int i,j,x,y;
	for(i=1;i<=n;++i)
		cin>>h[i];
	for(i=1;i<=m;++i){
		cin>>x>>y;
		add(x,y);
		add(y,x);
	}
	bool f;
	for(i=1;i<=n;++i){
		if(!vis[i]){
			f=1;
			for(j=head[i];j!=0;j=a[j].next){
				if(h[a[j].to]>=h[i]){
					f=0;
					break;
				}
				else
					vis[a[j].to]=1;
			}
			if(f)
				++ans;
		}
	}	
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 6796
#include <iostream>
using namespace std;
int main(){
  int a,b,c; cin >> a >> b >>c;
  if(a != b and b != c and c != a)
    cout << 3 << endl;
  else if((a == b and b != c) or (a != b and b == c) or (a == c and b != c))
    cout << 2 << endl;
  else
    cout << 1 << endl;
}

Measured memory_bytes: 3608
const INF: i64 = std::i64::MAX - 1;
fn prim(adjm: Vec<Vec<i64>>) -> i64 {
    let mut minc = vec![INF; adjm.len()];
    let mut used = vec![false; adjm.len()];
    let mut sum: i64 = 0;
    minc[0] = 0;
    loop {
        let m = {
            let mut i: usize = std::usize::MAX;
            let mut tmp = INF;
            for j in 0..adjm.len() {
                if !used[j] && tmp > minc[j] {
                    tmp = minc[j];
                    i = j;
                }
            }
            i
        };
        if m == std::usize::MAX {
            break;
        }
        sum += minc[m];
        used[m] = true;
        for j in 0..adjm[m].len() {
            if adjm[m][j] != -1 {
                minc[j] = min(minc[j], adjm[m][j]);
            }
        }
    }
    return sum;
}

fn solve() {
    let n = read();
    let mut adjm = vec![vec![-1; n]; n];
    for i in 0..n {
        for j in 0..n {
            adjm[i][j] = read();
        }
    }
    println!("{}", prim(adjm));
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========



Measured memory_bytes: 9084
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

n, *a = map(int, read().split())
dict = defaultdict(int)
ans = 0
for i in range(n - 1, -1, -1):
    ans += dict[-a[i] - i]
    dict[a[i] - i] += 1
print(ans)


Measured memory_bytes: 61712
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

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); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

using pii = pair<intmax_t, intmax_t>;
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<>>;

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
// }}} End

size_t N;
vector<vector<pii>> G(int(1e5));

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;

    for (size_t i = 0; i < N - 1; ++i) {
        intmax_t a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        G[a].emplace_back(b, c);
        G[b].emplace_back(a, c);
    }

    int Q, K; cin >> Q >> K;
    K--;

    MinHeap<pii> que;
    que.emplace(0, K);

    vector<intmax_t> dist(N, LINF);
    dist[K] = 0;

    while (!que.empty()) {
        intmax_t nowCost, nowNode;
        tie(nowCost, nowNode) = que.top();
        que.pop();
        for (auto nextNode: G[nowNode]) {
            if (chmin(dist[nextNode.first], dist[nowNode] + nextNode.second)) {
                que.emplace(dist[nextNode.first], nextNode.first);
            }
        }
    }

    dump(dist);

    while (Q--) {
        int x, y; cin >> x >> y;
        x--, y--;
        cout << dist[x] + dist[y] << "\n";
    }

    return 0;
}


Measured memory_bytes: 11120
import java.util.*;
 
class Main{
    Scanner sc = new Scanner(System.in);
 
    Main(){
    int a=sc.nextInt();
    int b=sc.nextInt();
    System.out.println( (a*b) + " " + (a*2+b*2) );
    }
 
    public static void main(String[] args){
    new Main();
    }
}


Measured memory_bytes: 26120
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	int x;
	FOR(i,1,m){
		cin>>x;
		n-=x;
	}
	if(n>=0){
		cout<<n<<'\n';
	}else cout<<"-1\n";
	RE 0;
}




Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	int x, a; cin >> x >> a;
	if (x < a) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

int gcd(int a, int b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(b, a % b);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    int g = gcd(n, m);
    int l = n / g * m;
    bool ans = true;
    if(s[0] != t[0]) ans = false;
    if(g != 1){
        if(n < m){
            swap(n, m);
            swap(s, t);
        }
        int tmp = (n / g) * (m / g);
        for(int i = 0; i < l; i += tmp){
            int ida = i / (m / g);
            int idb = i / (n / g);
            if(s[ida] != t[idb]){
                ans = false;
            }
        }
    }
    if(!ans) cout << -1 << endl;
    else cout << l << endl;
}

Measured memory_bytes: 640
k, n = map(int, input().split())
arr = list(map(int, input().split()))

m = []
for i in range(1, n):
	m += [arr[i] - arr[i - 1]]

mn = k - arr[-1] + arr[0]
m.append(mn)
m.sort()
print(sum(m[:n-1]))


Measured memory_bytes: 26444
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

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

    vector<P> v(m);  // v[i] : (鍵iの値段, 鍵iで開けられる宝箱の集合)
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        ll x = 0;
        rep(j, b) {
            ll c;
            cin >> c;
            x += 1<<(c-1);
        }
        v[i] = make_pair(a, x);
    }

    ll N = 1<<n;
    vvl dp(m+1, vl(N, INF));  // dp[i][s] : i個目の鍵までで集合sを開けるのに必要な費用の最小値
    dp[0][0] = 0;
    rep(i, m) {
        rep(s, N) {
            chmin(dp[i+1][s], dp[i][s]);
            chmin(dp[i+1][s | v[i].second], dp[i][s] + v[i].first);
        }
    }

    if(dp[m][N-1] == INF) {
        out(-1);
    }
    else {
        out(dp[m][N-1]);
    }

    re0;
}

Measured memory_bytes: 35356
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
#define all(a) begin(a),end(a)

int main()
{
    string S; cin >> S;
    int Q; cin >> Q;

    string pre, suf;

    int dir = 0;
    rep(i, Q) {
        int T; cin >> T;
        if (T == 1) {
            dir ^= 1;
        } else {
            int F;
            string C;
            cin >> F >> C;
            if ((F == 1 && dir == 0) or (F != 1 && dir != 0)){
                pre += C;
            } else {
                suf += C;
            }
        }
    }

    string ans;
    if (dir == 0) {
        reverse(all(pre));
        ans = pre + S + suf;
    } else {
        reverse(all(S));
        reverse(all(suf));
        ans = suf + S + pre;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
bool isprime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			return false;
		}
	}
	return true;
}

signed main(){
	int x;
	cin>>x;

	for(int i=x;i<100*x;i++){
		if(isprime(i)){
			cout<<i<<endl;
			return 0;
		}
	}


	return 0;
}



Measured memory_bytes: 3592
S = input()
N = len(S)
S2 = S[:int((N-1)/2)]
S3 = S[int((N+3)/2-1):]

def kaibun(string):
    if len(string) > 1:
        if string[0] == string[-1]:
            return kaibun(string[1:-1])
        else:
            return 0
    else:
        return 1

if kaibun(S)==1:
    if kaibun(S2) == 1:
        if kaibun(S3) == 1:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

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

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<string>> S(H, vector<string>(W));
	char c;
	int x;
	for (int i = 0;i < H;++i) {
		for (int j = 0;j < W;++j) {
			cin >> S[i][j];
			if (S[i][j] == "snuke") {
				c = 'A' + j;
				x = 1 + i;
			}
		}
	}
	cout << c << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
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;}

main() {
    int N,X; cin >> N >> X;
    int pos=X;int ans;
    rep(i,N){
        int x; cin >> x;
        pos=abs(pos-x);
        if(i==0)ans=pos;
        ans=gcd(ans,pos);
        pos=x;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int x = 0;
    cin >> x;

    for (int i = -118; i <= 119; i++) {
        for (int j = -118; j <= 119; j++) {
            if (pow(i, 5) - pow(j, 5) == x) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }    
}

Measured memory_bytes: 4096
#include <stdio.h>

int main(){
    int r,c;
    scanf("%d %d",&r,&c);
    
    int cell[101][101]={};
    int right[101]={};
    int down[101]={};
    int e = 0;
    
   
    
    
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            scanf("%d",&cell[i][j]);
        }
    }
    
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            down[j] += cell[i][j];
        }
    }
    
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            right[i] += cell[i][j];
        }
        
    }
    
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            printf("%d ",cell[i][j]);
        }
        printf("%d\n",right[i]);
    }
    for(int i = 0; i < c; i++){
        printf("%d ",down[i]);
        e += down[i];
    }
    printf("%d\n", e);
    
    
    
}



Measured memory_bytes: 2148
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline().strip()

h, w = [int(x) for x in input().split()]
g = [input() for _ in range(h)]
ans = 0
for si in range(h):
    for sj in range(w):
        if g[si][sj] != '#':
            d = [[-1 for j in range(w)] for i in range(h)]
            d[si][sj] = 0
            q = [(si, sj)]
            for i, j in q:
                ans = max(ans, d[i][j])
                for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                    ni, nj = i + di, j + dj
                    if 0 <= ni < h and 0 <= nj < w and g[ni][nj] != '#' and d[ni][nj] == -1:
                        d[ni][nj] = d[i][j] + 1
                        q.append((ni, nj))
print(ans)  


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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  string s;
  cin >> s;
  if (s.find('C') != string::npos && s.find('F') != string::npos && s.find('C') < s.find_last_of('F')) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
main :: IO()
main = do
  input <- getLine
  let [w,h,x,y,r] = map (\i -> read i :: Int) $ words input
  putStrLn $ if judge [w, h, x, y, r] then "Yes" else "No"
 
judge :: [Int] -> Bool
judge [w, h, x, y, r] = isInside r w x && isInside r h y
 
isInside :: Int -> Int -> Int -> Bool
isInside r m val = r <= val && val <= m - r

Measured memory_bytes: 3692
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	string ans = "Yes";

	if (S.size() % 2 == 1) ans = "No";
	else {
		for (int i=0; i<S.size(); i+=2) {
			if (!(S[i] == 'h' && S[i+1] == 'i')) {
				ans = "No";
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = input()
op_cnt = len(n) - 1  # すき間の個数
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き

    formula = ""
    for p_n, p_o in zip(n, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

Measured memory_bytes: 9028
from functools import reduce

def main():
    # 一文字のみを読み込み
    # s = input().rstrip().split(' ')
    
    # スペース区切りで標準入力を配列として読み込み
    # s = input().rstrip().split(' ')

    # 位置文字ずつ標準入力を配列として読み込み
    # s = list(input().rstrip())
    s = list(input().rstrip())
    dict = {}
    b_flag = True
    for char in s:
        if(char in dict.keys()):
            dict[char] = dict[char] + 1
        else:
            dict[char] = 1
        
    for v in dict.values():
        if v % 2 == 1:
            b_flag = False
    if b_flag:
        print('Yes')
    else:
        print('No')
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
S = input()

dif1 = 0
dif2 = 0

for i in range(len(S)):
	if i%2 == 0 and S[i] == '0':
		dif1 += 1
	if i%2 == 1 and S[i] == '1':
		dif1 += 1
	if i%2 == 0 and S[i] == '1':
		dif2 += 1
	if i%2 == 1 and S[i] == '0':
		dif2 += 1

print(min([dif1, dif2]))

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

int main(){
  int a,b,c;
  cin >> a;
  cin >> b;
  cin >> c;
  
  if(a < b){
     if(b < c){
        cout << "Yes" << endl;
     }else{
     cout << "No" << endl;
   }
  }else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
    int a[4], b[2];
    rep (i, 4) cin >> a[i];
    rep (i, 2) cin >> b[i];
    sort(a, a + 4);
    cout << a[1] + a[2] + a[3] + max(b[0], b[1]) << endl;

    return 0;
}


Measured memory_bytes: 3168
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
inva = [[0] * M for _ in range(N)]
for i in range(N):
  for j in range(M):
    inva[i][a[i][j] - 1] = j
dp = [N * M] * M
t = [0] * N
vis = set()
#print(inva)
for i in range(M):
  x = 0
  y = 0
  for j in range(M):
    z = 0
    for k in range(N):
      z += inva[k][j] == t[k]
    if z > y:
      y = z
      x = j
  dp[i] = y
  vis.add(x)
  for k in range(N):
    w = M
    for j in range(M):
      if j in vis: continue
      w = min(w, inva[k][j])
    t[k] = w
print(min(dp))

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

//#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 4e3 + 7;
const int N = 2e5 + 7;
const int M = 22;
const int mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,s;
int a[N];
int p[N];
int d[N];

int pw ( int x , int y )
{
    if( !y )return 1;
    if( (y & 1) ){
        return x * 1ll * pw( x , y - 1 ) % mod;
    } else{
        int xx = pw( x , y / 2 );
        return xx * 1ll * xx % mod;
    }
}

void solve1()
{
    cin >> n >> s;
    for( int i = 1; i <= n; i++ ){
        cin >> a[i];
    }
    p[0] = 1;
    for( int i = 1; i < N; i++ ){
        p[i] = p[i - 1] * 1ll * 2 % mod;
    }
    d[0] = p[n];
    p[n + 1] = pw( 2 , mod - 2 );
    for( int i = 1; i <= n; i++ ){
        for( int j = s; j >= 0; j-- ){
            d[j + a[i]] += d[j] * 1ll * p[n + 1] % mod;
            d[j + a[i]] %= mod;
        }
    }
    cout << d[s];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 4444
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1e9+7
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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;}

int main(){
    int n;
    cin >> n;
    vector<ll> A(n);
    rep(i,n) cin >> A[i];
    vector<ll> cum(n);
    cum[n-1]=A[n-1];
    for(int i=n-2;i>=0;i--){
        cum[i]=cum[i+1]+A[i];
    }
    ll ans=0;
    ll mod=inf;
    for(int i=0;i<n-1;i++){
        ans+=A[i]*(cum[i+1]%mod);
        ans%=mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6424
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	final static PrintStream so = System.out;
	final static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			int w = sc.nextInt();
			int h = sc.nextInt();
		
			if (w == 0 && h == 0) return;
			
			so.println(count(h, w));
		}
	}
	
	public static int count(int H, int W) {
		int[][] g = new int[H][W];
		
		for (int h = 0; h < H; h++) {
			for (int w = 0; w < W; w++) {
				g[h][w] = sc.nextInt();
			}
		}
		
		int count = 0;
		int[] mh = {0, 1, 0, -1, 1, 1, -1, -1};
		int[] mw = {1, 0, -1, 0, -1, 1, 1, -1};
		
		for (int h = 0; h < H; h++) {
			for (int w = 0; w < W; w++) {
				if (g[h][w] == 1) {
					Deque<Point> deq = new ArrayDeque<>();
					
					deq.push(new Point(h, w));

					while(!deq.isEmpty()) {
						Point current = deq.pop();
						g[current.h][current.w] = 0;
						
						for (int m = 0; m < mh.length; m++) {
							int nextH = current.h + mh[m];
							int nextW = current.w + mw[m];
							
							if (nextH >= H || nextH < 0 || nextW >= W || nextW < 0) continue;
							
							if (g[nextH][nextW] == 1) {
								deq.push(new Point(nextH, nextW));
							}
						}
					}
					count++;
				}
			}
		}
		
		return count;
	}
	
	static class Point {
		int h;
		int w;
		public Point(int h, int w) {
			this.h = h;
			this.w = w;
		}
		
		@Override
		public boolean equals(Object obj) {
			if (obj == null) return false;
			if (!(obj instanceof Point)) return false;
			Point that = (Point) obj;
			return this.h == that.h && this.w == that.w;
		}
	}
}



Measured memory_bytes: 46660
#include<stdio.h>
int main() {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    int i,keep;
    for (i = 0; i < 2; i++) {
        if (a > b) {
            keep = a;
            a = b;
            b = keep;
        }
        if (b > c) {
            keep = b;
            b = c;
            c = keep;
        }
    }
    int ans = 0;
    ans += c - b;
    a += c - b;
    if ((c - a) % 2 == 0)
        ans += (c - a) / 2;
    else
        ans += (c - a) / 2 + 2;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

const ll MOD = 1e9 + 7;

vector<ll> sumup(const vector<ll>& a) {
  int N = a.size();
  vector<ll> res(N + 1, 0);
  for (int i = 0; i < N; i++) res[i + 1] = (res[i] + a[i]) % MOD;
  return res;
}

int main() {
  int N, K;
  while (cin >> N >> K) {
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    vector<ll> dp(K + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < N; i++) {
      auto sum = sumup(dp);
      vector<ll> ndp(K + 1, 0);
      for (int s = 0; s <= K; s++) {
        ndp[s] = (sum[s + 1] - sum[max(0, s - a[i])] + MOD) % MOD;
      }
      dp = ndp;
    }
    cout << dp[K] << endl;
  }
  return 0;
}


Measured memory_bytes: 2648
import copy
N = int(input())
P = [int(a) for a in input().split()]
Q = [int(a) for a in input().split()]

nP = 0
nQ = 0
xs = []
def suretsu(x):
    if len(x) == N:
        xs.append(x)
        return
    else:
        for n in range(1, N+1):
            if n not in x:
                new_x = copy.deepcopy(x)
                new_x.append(n)
                suretsu(new_x)

suretsu([])
for i, x in enumerate(xs):
    is_P = True
    is_Q = True
    for j in range(N):
        if P[j]!=x[j]:
            is_P = False
        if Q[j]!=x[j]:
            is_Q = False
    if is_P:
        nP = i+1
    if is_Q:
        nQ = i+1

print(abs(nP-nQ))

Measured memory_bytes: 14808
class Dice:
    dice = {'N':2, 'E':4, 'S':5, 'W':3}
    currTop = 1

    def top(self):
        return self.currTop

    def rot(self, direction):
        newTop = self.dice[direction]
        currTop = self.currTop
        self.currTop = newTop
        if direction == 'N':
            self.dice['N'] = 7 - currTop
            self.dice['S'] = currTop
        elif direction == 'S':
            self.dice['N'] = currTop
            self.dice['S'] = 7 - currTop
        elif direction == 'E':
            self.dice['E'] = 7 - currTop
            self.dice['W'] = currTop
        elif direction == 'W':
            self.dice['E'] = currTop
            self.dice['W'] = 7 - currTop

    def yaw(self, direction):
        newDice = {}
        if direction == 'E':
            newDice['N'] = self.dice['E']
            newDice['E'] = self.dice['S']
            newDice['S'] = self.dice['W']
            newDice['W'] = self.dice['N']
        if direction == 'W':
            newDice['N'] = self.dice['W']
            newDice['E'] = self.dice['N']
            newDice['S'] = self.dice['E']
            newDice['W'] = self.dice['S']
        self.dice = newDice

faces = list(map(int, input().split()))
q = int(input())
d = Dice()

for i in range(q):
    top, front = list(map(int, input().split()))
    topIdx = faces.index(top) + 1
    frontIdx = faces.index(front) + 1

    if d.top() != topIdx:
        # search topIdx and rotate to make topIdx top.
        key = [k for k,v in d.dice.items() if topIdx == v]
        if len(key) == 0:
            d.rot('N')
            key = [k for k,v in d.dice.items() if topIdx == v]
        d.rot(key[0])

    # rotate(yaw) to make frontIdx front.
    while True:
        if d.dice['N'] == frontIdx:
            break
        d.yaw('E')

    print(faces[d.dice['W']-1])

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

void hawawa()
{
  string str;
  cin >> str;
  if (str.size() == 2) {
    if (str[0] == str[1]) {
      cout << "1 2\n";
    } else {
      cout << "-1 -1\n";
    }
    return;
  }
  for (int i = 0; i + 2 < str.size(); i++) {
    if (str[i] == str[i + 1] || str[i] == str[i + 2] || str[i + 1] == str[i + 2]) {
      cout << i + 1 << " " << i + 3 << "\n";
      return;
    }
  }
  cout << "-1 -1\n";
}

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


Measured memory_bytes: 512
N = int(input())
A = [[int(x) for x in input().split()]for i in range(N)]
T = 0            ####現在時刻
place = (0,0)    ####現在地
for i in range(N):
  if ((A[i][0]-T) + abs(A[i][1]-place[0]) + abs(A[i][2]-place[1]))%2 == 1 or (A[i][0]-T) < abs(A[i][1]-place[0]) + abs(A[i][2]-place[1]):
    print("No")
    exit()
  else:
    T = A[i][0]
    place = (A[i][1], A[i][2])
print("Yes")

Measured memory_bytes: 60952