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

public class Main {
    public static void main(String[] args) {
         Scanner sc = new Scanner(System.in);
         while (true) {
             int H = sc.nextInt();
             int W= sc.nextInt();
             if (H == 0 && W == 0) {
             break;
             }
             for(int i=0;i<H;i++){
                 for(int j=0;j<W;j++){
                     if((j+i)%2==0){
                         System.out.printf("#");
                     }else System.out.printf(".");
                 }
                 System.out.printf("\n");
             }
             System.out.printf("\n");
         }
    }
}


Measured memory_bytes: 61860
n, m = map(int, input().split())
k_s = list(list(int(i) for i in input().split()) for i in range(m))
p = list(map(int, input().split()))

ans = 0
temp1 = 0
temp2 = 0

for i in range(2 ** n):
    num = bin(i)
    num2 = num.lstrip('0b')
    num3 = num2.zfill(n)
    
    for j in range(m):
        for l in range(k_s[j][0]):
            temp1 += int(num3[k_s[j][l + 1] - 1])
        if temp1 % 2 == p[j]:
            temp2 += 1
            temp1 = 0
        else:
            temp1 =0
    
    if temp2 == m:
        ans += 1
    temp2 = 0
    
print(ans)

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

int main()
{
	int N;
	cin >> N;
	map<string, int> mp;
	for( int i = 0; i < N; i++ ) {
		string S;
		cin >> S;
		mp[S]++;
	}

	cout << "AC x " << mp["AC"] << endl;
	cout << "WA x " << mp["WA"] << endl;
	cout << "TLE x " << mp["TLE"] << endl;
	cout << "RE x " << mp["RE"] << endl;
}


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

int main()
{
	int n,m,a[50],b[50],c[50],d[50];
	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>a[i]>>b[i];
	for(int i=0;i<m;i++) cin>>c[i]>>d[i];
	
	int minv,v[50];
	for(int i=0;i<n;i++){
		minv=abs(a[i]-c[0])+abs(b[i]-d[0]);
		v[i]=1;
		for(int j=1;j<m;j++){
			if(minv>abs(a[i]-c[j])+abs(b[i]-d[j])){
				minv=abs(a[i]-c[j])+abs(b[i]-d[j]);
				v[i]=j+1;
			}
		}
	}
	
	for(int i=0;i<n;i++) cout<<v[i]<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector <int> adj[100004];
int a[100004];
bool visited[100004];
int nodes,edges,pora = 0;
int main()
{
    cin>>nodes>>edges;
    for(int i =0;i<edges;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=0;i<=nodes;i++)
    {
        visited[i] = false;
        a[i] = 0;
        sort(adj[i].begin(),adj[i].end());
    }
    queue <int> que;
    que.push(1);
    visited[1] = true;
    while(!que.empty())
    {
        int u,node = que.front();
        que.pop();
        for(int i=0;i<adj[node].size();i++)
        {
            u = adj[node][i];
            if(!visited[u])
            {
                visited[u] = true;
                a[u] = node;
                que.push(u);
                pora++;
            }
        }
    }
    //printf("%d pora\n",pora);
    if(pora != nodes-1)
        printf("No\n");
    else
    {
        printf("Yes\n");
        for(int i=2;i<=nodes;i++)
            printf("%d\n",a[i]);
    }
    return 0;
}


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

int main()
{
  	int a,b,ans;
  	char op;
  
 	cin >> a >> op >> b;
  
 	while(op != '?'){
      switch(op){
        case '+' : ans = a + b;break;
        case '-' : ans = a - b;break;
        case '*' : ans = a * b;break;
        case '/' : ans = a / b;break;
      }
      cout << ans << endl;
      
      cin >> a >> op >> b;
    }
}


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

int main() {
    int N, P;
    int L[3];
    cin >> N;

    P = 0;
    for(int i=0; i<=2; i++){
        L[i] = N % 10;
        N = N / 10;
        if (L[i] == 7){
            P = 1;
        }
    }
    if(P == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main(){
	
	long long A, B;
	cin >> A >> B;
	
	if((A + B) % 2 == 0){
		cout << ((A + B) / 2) << endl;
	}else{
		cout << "IMPOSSIBLE" << endl;
	}
	
	return 0;
}

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

using namespace std;
using ll = long long;

ll solve(ll N, ll K, const vector<ll>& ps, const vector<ll>& cs)
{
    ll ans = -2000000000000000001LL;

    for (ll i = 1; i <= N; ++i)
    {
        auto j = i;
        ll sum = 0, len = 0, res = 0;

        do
        {
            ++len;
            sum += cs[ps[j]];
            j = ps[j];
        } while (j != i);

        auto T = min(len, K);
        j = i;

        for (int k = 0; k < T; ++k)
        {
            res += cs[ps[j]];
            ans = max(ans, res);
            j = ps[j];
        }

        auto left = K - T;

        if (left == 0 or sum < 0)
            continue;

        auto t = left / len;

        if (t > 1)
        {
            res += (t - 1)*sum;
            ans = max(ans, res);
            left -= (t - 1)*len;
        }

        for (int k = 0; k < left; ++k)
        {
            res += cs[ps[j]];
            ans = max(ans, res);
            j = ps[j];
        }
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;

    vector<ll> ps(N + 1), cs(N + 1);

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

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

    auto ans = solve(N, K, ps, cs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int l = a + b;
  int r = c + d;
  if(l > r)
    cout << "Left" << endl;
  else if (l == r)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
ll a[55], b[55], c[55], d[55];
ll mx = 0;
int n, m, q;
vector<int> cur;
void dfs(int u) {
  if (u == n) {
    ll temp = 0;
    // for (int i = 1; i <= n; i++) {
    //   cout << cur[i] << ' ';
    // }
    // cout << endl;
    for (int i = 1; i <= q; i++) {
      if (cur[b[i]] - cur[a[i]] == c[i]) {
        // cout << i << ' ';
        temp += d[i];
      }
    }
    // cout << temp << endl;
    mx = max(mx, temp);
    return;
  }
  for (int i = max(cur.back(), 1); i <= m; i++) {
    cur.pb(i);
    dfs(u + 1);
    cur.pop_back();
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m >> q;
  cur.pb(1);
  for (int i = 1; i <= q; i++)
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  dfs(0);
  cout << mx << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MAXN = 1e5+10;

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

void solve() {
  vector<P> v;
  for (int i=0;i<n;i++) {
    v.push_back(P(a[i], b[i]));
  }
  sort(v.begin(), v.end());
  ll cost = 0;
  for (int i=0;i<n && m > 0;i++) {
    int tmp = min(m, v[i].second);
    cost += v[i].first * tmp;
    m -= tmp;
  }
  cout << cost << endl;
}

int main() {
  cin >> n >> m;
  for (int i=0;i<n;i++) {
    cin >> a[i] >> b[i];
  }
  solve();
}


Measured memory_bytes: 4084
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

vl divisor(ll k){
    vl c;
    for(ll i=1; i*i<=k; i++){
        if(k % i == 0){
            c.push_back(i);
            if((k / i) != i){
                c.push_back(k/i);
            }
        }
    }
    sort(c.begin(), c.end());
    return c;
}

int main(){
    ll n,m; cin >> n >> m;
    vl div = divisor(m);
    ll ans = 0;
    for(auto i : div){
        if(n * i <= m) ans = i;
        else break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<limits.h>

using namespace std;

 int minimum(int h[],int arr_size,int val[])
 {
     val[0]=0;
     int j1,j2,temp1,temp2;
     /*cout<<"init:\t";
     for(int i=0 ;i <arr_size;i++)
     {
         cout<<val[i]<<"\t";
     }*/
     for(int i=1 ;i<arr_size ;i++)
     {
         j1=i-1;
         j2=i-2;
         //cout<<j2<<"\n";
         temp1=abs(h[i]-h[j1])+val[j1];
         //cout<<"t1="<<temp1<<"\t";
         if(j2==-1)
         {
             h[j2]=INT_MAX;
             val[j2]=0;
             temp2=abs(h[j2]-h[i])+val[j2];
             //cout<<"t2="<<temp2<<"\n";
         }
         else
         {
              temp2=abs(h[j2]-h[i])+val[j2];
               // cout<<"te2="<<temp2<<"\n";
         }

         //cout<<"temp1="<<temp1<<"\n";
         //cout<<"temp2="<<temp2<<"\n";
         if(temp1<temp2)
         {
             //cout<<"min="<<temp1<<"\n";
             val[i]=temp1;
         }
         else
         {
            // cout<<"min="<<temp2<<"\n";
             val[i]=temp2;
         }
     }
     /*cout<<"fin:\t";
     for(int i=0 ;i <arr_size;i++)
     {
         cout<<val[i]<<"\t";
     }swsaa
     cout<<"\n";*/
     return val[arr_size-1];
 }

 int main()
 {
     int n;
     //cout<<"arr size";
     cin>>n;
     int arr[n],val[n];
     //val[0]=0;
     for(int i = 0 ;i < n ; i++)
     {
         cin>>arr[i];
     }
     /*cout<<"array:\t";
     for(int i = 0 ;i < n ; i++)
     {
         cout<<arr[i]<<"\t";
     }
     cout<<"\n";*/
     cout<<minimum(arr,n,val);
     return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int main()
{
	int n;
	cin>>n;
	VII dp(3,vector<ll>(n,-INF));
	VII a(3,vector<ll>(n,0));
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)cin>>a[j][i];
	dp[0][0] = a[0][0];
	dp[1][0] = a[1][0];
	dp[2][0] = a[2][0];
	//cout<<endl;
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++)
		{
			dp[j][i] = max(dp[j][i],dp[(j+1)%3][i-1]+a[j][i]);
			dp[j][i] = max(dp[j][i],dp[(j+2)%3][i-1]+a[j][i]);
		  //  cout<<dp[j][i]<<" ";
		}
		//cout<<endl;
	}
	ll ans = max(dp[2][n-1],dp[1][n-1]);
	ans = max(ans,dp[0][n-1]);
	cout<<ans;
}
	
	
	
	

Measured memory_bytes: 8680
#include <iostream>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

int main() {
    float A, B;
    cin >> A; 
    cin >> B;
    // cout << A << " " << B << endl;
    int result = 0;
    float maxA = (A+1) * 100 / 8;
    float minA = A * 100 / 8;
    float maxB = (B+1) * 10;
    float minB = B * 10;
    // cout << "maxA: " << maxA << " " << minA << endl;
    // cout << "maxB: " << maxB << " " << minB << endl;
    if(minA > minB) {
        if(minA < maxB) {
            cout << ceil(minA) << endl;
        } else {
            cout << -1 << endl;
        }
    } else {
        if (maxA > minB) {
            cout << ceil(minB) << endl;
        } else {
            cout << -1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 1e5;
ll a, b, c;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b >> c;
  ll d = c-a-b;
  cout << ((d>=0 && a*b*4<d*d) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3604
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void raushan_kumar(){
	string s,t;cin>>s>>t;
	int n=s.length(),m=t.length();
	int dp[n+1][m+1];
	mset(dp,0);
	fo1(i,n){
		fo1(j,m){
			if(s[i-1]==t[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	int ans=-1;
	int x,y;
	fo0(i,n+1){
		fo0(j,m+1){
			if(dp[i][j]>ans){
				ans=dp[i][j];
				x=i,y=j;
			}
		}
		// cout<<endl;
	}
	string out = "";
    int i = s.size(), j = t.size();
    while(i != 0 and j != 0){
        if(s[i-1] == t[j-1])out.push_back(s[i-1]), i--, j--;
        else if(dp[i-1][j] > dp[i][j-1])i--;
        else j--;
    }
    reverse(out.begin(), out.end());
    cout << out;
}

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

}

Measured memory_bytes: 70784
#include <iostream>

using namespace std;

int main(){
    int a, b, c;
    int sum1, sum2, sum3;
    cin >> a >> b >> c;
    sum1 = a + b;
    sum2 = a + c;
    sum3 = b + c;
    
    cout << min(sum1, min(sum2, sum3)) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

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

   vector<vector<int>> s(m);
   rep(i,m){
      int k;
      cin>>k;
      rep(j,k){
         int a;
         cin>>a;
         a--;
         s[i].push_back(a);
      }
   }
   vector<int> p(m);
   rep(i,m){
      cin>>p[i];
   }
   ll ans=0;
   for(int bit=0;bit<(1<<n);bit++){
      bool f=true;
      for(int i=0;i<m;i++){
         int count=0;
         for(auto v:s[i]){
            if(bit &(1<<v)) count++;
         }
         if(count%2!=p[i]) f=false; 
      }
      if(f==true) ans++;     
   }  
   cout<<ans<<endl;


return 0;
}



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

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static private long Solve(int N, int K)
        {
            if (K == 0)
            {
                return Math.BigMul(N, N);
            }
            else
            {
                long sum = 0;
                for (int i = 1; K + i <= N; ++i)
                {
                    int b = K + i;
                    sum += (N / b) * i;
                    sum += Math.Max(N % b - K + 1, 0);
                }
                return sum;
            }
        }
        static void Main(string[] args)
        {
            int[] values = ReadInts();
            Console.WriteLine(Solve(values[0], values[1]));
        }
    }
}


Measured memory_bytes: 11220
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
using namespace std;
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;
const ll inf = 0x3f3f3f3f3f3f3f3f;
#define ull unsigned long long
const int maxn = 2e6+10;
const ll mod=1e9+7;
#define MAXN 40100
ll gcd(ll T, ll b) { return b == 0 ? T : gcd(b, T % b); }
ll lcm(ll T, ll b) { return T / gcd(T, b) * b; }
ll mul(ll a,ll b, ll c) {
    ll ans = 0;
    while(b) {
        if(b&1) {
            ans= (ans+a)%c;
            b--;
        }
        b>>=1;
        a=(a+a)%c;
    }
    return ans;
}
 
ll powmod(ll a,ll b,ll c) {
    ll ans = 1;
    while(b) {
        if(b&1) {
            ans = mul(ans,a,c);
            b--;
        }
        b>>=1;
        a=mul(a,a,c);
    }
    return ans ;
}
 
ll exgcd(ll a,ll b,ll &x,ll &y) {
    if(b==0)
    {
        x=1;y=0;
        return a; 
    }
    ll r=exgcd(b,a%b,x,y);
    ll temp=y;
    y=x-(a/b)*y;
    x=temp;
    return r;
}

const ll INF = 0x3f3f3f3f3f3f3f3f;

ll a[maxn];
int main() {
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        sum=(sum+a[i])%mod;
    }
    ll ans=0;
    for(int i=1;i<n;i++) {
        sum=(sum+mod-a[i])%mod;
        ans=(ans+(a[i]*sum)%mod)%mod;
    }
    cout<<ans<<endl;

    return 0;
}






Measured memory_bytes: 5144
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
signed main()
{
    fast;
    string s;
    cin>>s;
    int n = s.size();
    int wins = 15-n;
    for(int i=0;i<n;i++)
        if(s[i]=='o')
            wins++;
    if(wins>=8)
        cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
ans=N
A.sort()

asum=[A[0]]
j=1
for i in range(1,N):
    if asum[i-1]*2<A[i]:
        ans-=j
        j=0
    asum.append(asum[i-1]+A[i])
    j+=1
    
print(ans)

Measured memory_bytes: 20404
#include <cstdio>
#include <numeric>
 
int const N = 1000001;
 
int spf[N], u[N], s[17], d, i, j, k;
char const *r = "pairwise";
 
int main() {
    while (++i < N) spf[i] = i;
    for (i = 2; i * i < N; i++)
        for (j = i * i; j < N; j += i)
            if (spf[j] == j) spf[j] = i;
    for ((void)scanf("%*d"); ~scanf("%d", &j);) {
        d = std::gcd(d, j);
        for (; j > 1; j /= i)
            if (u[s[k++] = i = spf[j]]) r = "setwise";
        while (k) u[s[--k]] = 1;
    }
    printf("%s coprime\n", d > 1 ? "not" : r);
    return 0;
}


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

using namespace std;

int main() {
  int n;
  char s[200];
  cin >> n;

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

  for (int i = 0; i < n; ++i) {
    if (s[i] == 'Y') {
      cout << "Four" << endl;
      return 0;
    } else {
      continue;
    }
  }
  cout << "Three" << endl;
}


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

int main (){
  int A,B;
  cin >>A>>B;
  if ((A>=B)&(B!=1)){
    cout <<"1"<<endl;
  }
  else if(B ==1){
    cout <<"0"<<endl;
  }
  
  else{
    int sum =A;
    int count=1;
    while(sum<B){
      sum +=(A-1);
      count++;
    }
    cout <<count<<endl;
  }
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL T[1000],A[1000];

LL ans = 0;

void solve(){
	LL t = 1,a = 1;
	for(int i=0;i<N;i++){
		LL n = max(t/T[i] + (t%T[i]!=0),a/A[i] + (a%A[i]!=0));
		t = n*T[i];
		a = n*A[i];
	}
	ans = t + a;
}
 
int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> T[i] >> A[i];
 
    solve();

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

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
while (true) {
int n = sc.nextInt();
if (n == 0) { break; }
int[] scores = new int[n];
for (int i = 0; i < scores.length; i++) {
scores[i] = sc.nextInt();
}
double average = 0, variance = 0;
for(int i1=0;i1<n;i1++){
	average=average+scores[i1];
}
average=average/n;
for(int i2=0;i2<n;i2++){
	variance=variance+(average-scores[i2])*(average-scores[i2]);
}
variance=variance/n;
System.out.println(Math.sqrt(variance));
}
}
}
}


Measured memory_bytes: 31356
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	char s[100],t[50];
	int i,j,f=0;
	chin(s);
	chin(t);
	rev(i,strlen(s)){
		rep(j,strlen(t)){
			if(s[i+j]!='?'&&s[i+j]!=t[j])
				break;
		}
		if(j==strlen(t)){
			f=1;
			rep(j,strlen(t)){
				s[i+j]=t[j];
			}
			break;
		}
	}
	if(f){
		rep(i,strlen(s)){
			if(s[i]=='?')
				putchar('a');
			else
				putchar(s[i]);
		}
		puts("");
	}
	else
		puts("UNRESTORABLE");
	return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
        var n, d, x int
        fmt.Scanln(&n)
        fmt.Scanf("%d %d\n", &d, &x)

        for i := 0; i < n; i++ {
                var a int
                fmt.Scanln(&a)
                for j := 0; j < d; j += a {
                        x++
                }
        }
        fmt.Println(x)
}

Measured memory_bytes: 512
def sort_str(s):
    l = list(s)
    l.sort()
    return ''.join(l)

n = int(input())
counts = dict()
for _ in range(n):
    s = input()
    s = sort_str(s)
    counts.setdefault(s, 0)
    counts[s] += 1
ans = 0
for c in counts.values():
    ans += c * (c - 1) // 2
print(ans)


Measured memory_bytes: 17892
n, a, b = map(int, input().split())

def degitalsum(i):
  s = str(i)
  array = list(map(int, s))
  return sum(array)

ans = 0

for i in range(1, n + 1):
  if a <= degitalsum(i) <= b:
    ans += i

print(ans)  


Measured memory_bytes: 3060
lap_distance, house_count = gets.split.map(&:to_i)
distance_list = gets.split.map(&:to_i)

def section_data(d, p1, p2)
  {
    distance: d,
    start_point_index: p1,
    end_point_index: p2
  }
end

sections = distance_list.map.with_index do |distance, index|
  if index + 1 == distance_list.size
    section_data(distance_list[0] + (lap_distance - distance), 0, index + 1)
  else
    section_data(distance_list[index + 1] - distance, index, index + 1)
  end
end

longest_section = sections.max { |x, y| x[:distance] <=> y[:distance] }
#index = sections.find_index(longest_section)
#sections.delete_at(index)

#p sections.inject(0) { |result, v| result + v[:distance].to_i }

p lap_distance - longest_section[:distance]

Measured memory_bytes: 67708
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int A[100005] = {};
    for(int i = 1; i <= n; i++)
    {
        cin >> A[i];
    }
    int tem = A[n];
    for(int i = n-1; i >= 1; i--)
    {
        if(A[i] > tem)
        {
            A[i]--;
            if(A[i] == tem)
            {
                tem = A[i];
            }
            else
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            tem = A[i];
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 100010;
bool vst[N];
vector<int> mp[N];
int dep[N];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int main() 
{
	int n, m;
	n = read();
	m = read();
	for(int i = 1; i <= m; i ++) 
	{
		int x, y;
		x = read();
		y = read();
		mp[x].push_back(y);
		mp[y].push_back(x);
	}
	ll cnt[2] = {0, 0};
	ll siz1(0);
	fill(vst + 1, vst + 1 + n, 0);
	for(int i = 1; i <= n; i ++) 
		if(!vst[i]) 
		{
			vector<int> q;
			q.push_back(i);
			vst[i] = 1;
			dep[i] = 0;
			bool isBip(1);
			for(int op(0); op < (int)q.size(); op ++) 
			{
				int v(q[op]);
				for(int y : mp[v]) 
					if(!vst[y]) 
					{
						vst[y] = 1;
						q.push_back(y);
						dep[y] = dep[v] + 1;
					}
					else 
						if((dep[v] - dep[y]) % 2 == 0) 
							isBip = 0;
			}
			if(q.size() == 1) siz1 += q.size();
			else cnt[isBip]++;
		}
	ll ans(0);
	ans += siz1 * siz1 + 2 * siz1 * (n - siz1);
	ans += (cnt[0] + cnt[1]) * (cnt[0] + cnt[1]);
	ans += cnt[1] * cnt[1];
	cout << ans << endl;
}	


Measured memory_bytes: 7932
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define srep(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)

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

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

double dp[3000][3000];

int main() {
  int n;
  cin >> n;
  vector<double> p(n,0);
  rep(i,n) cin >> p.at(i);

  dp[0][0] =1;
  rep(i,n) {
    rep(j,n+1) {
      if(j-1>=0) dp[i+1][j] += (dp[i][j-1] * p.at(i));
      dp[i+1][j] += (dp[i][j]*(1-p.at(i)));
    }
  }

  double ans=0;

  srep(i,n/2+1,n+1) {
      ans+=dp[n][i];
  }
  fcout << ans << endl;
  return 0;
}


Measured memory_bytes: 70528
n = int(input())
lis = []
cou = 0
num = 1
while n > cou:
  cou += num
  num += 1
  lis.append(cou)
  if cou > n:
    print("No")
    exit()
  if n == cou:
    break
print("Yes")
print(len(lis)+1)
lis.sort(reverse=True)
ans = [[str(len(lis))] for i in range((len(lis)+1))]
nu = 1
num = len(lis)
for i in range(num):
  for k in range(i+1,num+1):
    ans[i].append(str(nu))
    ans[k].append(str(nu))
    nu += 1
for i in range(num+1):print(" ".join(ans[i]))

Measured memory_bytes: 17140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
//#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
ll mod,dp[505][255];
int a[505],b[505];
vector<P>vec;
int main(){
	cin >> n >> mod;
	for(int i=0;i<n;i++){
		for(int j=0;j<2*n;j++){
			if(i*i+j*j < n*n) a[i]++;
			if(i*i+j*j <= 4*n*n) b[i]++;
		}
		vec.pb(mp(a[i],0));
	}
	for(int i=n;i<2*n;i++){
		for(int j=0;j<2*n;j++){
			if(i*i+j*j <= 4*n*n) b[i]++;
		}
		vec.pb(mp(b[i],1));
	}
	SORT(vec);
	ll ans = 0;
	for(int numm=0;numm<=n;numm++){
		rep(i,505)rep(j,255) dp[i][j] = 0;
		dp[0][0] = 1;
        int one = 0;
	    int cur = n-1;
		for(int i=0;i<vec.size();i++){
			int num = vec[i].fi;
			int ty = vec[i].sc;
			for(int j=0;j<=numm;j++){
				if(dp[i][j] == 0) continue;
				if(ty == 1){
					if(num-j-one >= 1){
						dp[i+1][j] += dp[i][j] * (num-j-one) % mod;
						if(dp[i+1][j] >= mod) dp[i+1][j] -= mod;
					}
				}
				else{
					if(b[cur]-n-numm-(n-1-cur-j) >= 1){
						dp[i+1][j] += dp[i][j] * (b[cur]-n-numm-(n-1-cur-j)) % mod;
						if(dp[i+1][j] >= mod) dp[i+1][j] -= mod;
					}
					if(a[cur]-one-j >= 1){
						dp[i+1][j+1] += dp[i][j] * (a[cur]-one-j) % mod;
						if(dp[i+1][j+1] >= mod) dp[i+1][j+1] -= mod;
					}
				}
			}
			if(ty == 1) one++;
			else cur--;
		}
		
		assert(one == n && cur == -1);
		if(numm%2 == 0) ans += dp[2*n][numm];
		else ans -= dp[2*n][numm];
	}
	cout << (ans%mod+mod)%mod << endl;
}

Measured memory_bytes: 1280
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     // pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
// int binary_search(int key) {
//     int ng = -1;
//     int ok = (int)a.size();
//     while(abs(ok - ng) > 1) {
//         int mid = (ok + ng) / 2;
//         if(isOK(mid, key))
//             ok = mid;
//         else
//             ng = mid;
//     }
//     return ok;
// }
// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W

int main() {
    int N, K;
    cin >> N >> K;

    double ans = 0;
    for(int i=1; i<=N; i++){
        int sum = i;
        double p = (double)1/N;
        while(sum < K){
            sum *= 2;
            p /= 2;
        }
        ans += p;
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if (n%2==0||n%5==0)cout<<"-1\n";
	else
	{
		int k=7%n, ans=1;
		while (k!=0)
		{
			ans++;
			k*=10;
			k+=7;
			k%=n;
		}
		cout<<ans<<"\n";
	}
}

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

using namespace std;

const int md = 1e9 + 7;

int n, c;
int a[444], b[444];
long long f[444][444], g[444][444], s[444];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d%d",&n,&c);
	for(int i = 1; i <= n; ++i) scanf("%d",&a[i]);
	for(int i = 1; i <= n; ++i) scanf("%d",&b[i]);
	for(int i = 1; i <= 400; ++i){
		g[i][0] = 1;
		for(int j = 1; j <= 400; ++j){
			g[i][j] = g[i][j - 1] * i % md;
		}
	}
	f[0][0] = 1;
	for(int i = 1; i <= n; ++i){
		memset(s, 0, sizeof(s));
		for(int j = a[i]; j <= b[i]; ++j){
			for(int k = 0; k <= c; ++k){
				s[k] += g[j][k];
				s[k] %= md;
			}
		}
		for(int j = 0; j <= c; ++j){
			for(int k = 0; k <= j; ++k){
				f[i][j] += f[i - 1][j - k] * s[k];
				f[i][j] %= md;
			}
		}
	}
	printf("%lld",f[n][c]);
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  if (a1 + a2 + a3 >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//file_name:ABC61_C.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int cmp1(const void *a, const void *b){ // 昇順
    // qsort
    // http://www.cc.kyoto-su.ac.jp/~yamada/ap/qsort.html

    return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b){ // 降順
    // qsort
    // http://www.cc.kyoto-su.ac.jp/~yamada/ap/qsort.html

    return *(int*)b - *(int*)a;
}

int main() {
    int n;
    ll k;
    scanf("%d%lld",&n,&k);
    int a[n][2] = {};
    rep(i,n){
        scanf("%d%d",&a[i][0],&a[i][1]);
    }
    qsort(a, n, sizeof(a[0]), cmp1); // 1列目で昇順ソート


    ll ans = 0;
    ll count = 0;
    rep(i,n){
        count += a[i][1];
        if(count>=k){
            ans = a[i][0];
            break;
        }
    }

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




Measured memory_bytes: 1788
#!/usr/bin/env python
from collections import deque

def main():
    H, W = map(int, input().split())
    grid = [None] * H
    white = 0
    for i in range(H):
        grid[i] = input()
        white += grid[i].count('.')

    q = deque()
    q.append([0, 0, 1])
    opt = ((0, 1), (0, -1), (1, 0), (-1, 0))
    visited = set()

    while q:
        y, x, dist = q.popleft()
        if grid[y][x] == '#':
            continue
        if (y, x) in visited:
            continue
        visited.add((y, x))
        if y == H-1 and x == W-1:
            print(white - dist)
            exit()
        for dy, dx in opt:
            if 0 <= y+dy < H and 0 <= x+dx < W:
                q.append([y+dy, x+dx, dist+1])
    print(-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
N,Q = map(int, input().split())
S = input()
A = [0]*N


for i in range(1, N):
    if S[i-1] == "A" and S[i] =="C":
        A[i] = A[i-1]+1
    else:
        A[i] = A[i-1]

for i in range(Q):
    a, b = map(int, input().split())
    print(A[b-1] - A[a-1])


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

int main(){
  int x, y, z, k; cin >> x >> y >> z >> k;
  vector<ll> a(x),b(y),c(z);

  for(ll i = 0; i < x; i++){
    cin >> a[i];
  }
  for(ll i = 0; i < y; i++){
    cin >> b[i];
  }
  for(ll i = 0; i < z; i++){
    cin >> c[i];
  }
  
  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  
  vector<ll> apb(x*y);
  for(ll i = 0; i < x; i++){
    for(ll j = 0; j < y; j++){
      apb[i*y + j] = a[i] + b[j];
    }
  }
  sort(apb.begin(), apb.end(), greater<ll>());
  ll minkxy = min(x * y, k);
  
  vector<ll> ans(minkxy * z);
  for(ll i = 0; i < minkxy; i++){
    for(ll j = 0; j < z; j++){
      ans[i*z + j] = apb[i] + c[j];
    }
  }
  
  sort(ans.begin(), ans.end(), greater<ll>());
  
  for(ll i = 0; i < k; i++){
    cout << ans[i] << endl;
  }
  
}

Measured memory_bytes: 31616
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

bool sosuu(int num) {
	if (num < 2)return false;
	else if (num == 2)return true;
	else if (num % 2 == 0)return false;

	long double b = num;
	long double a = sqrt(b);
	for (int i = 3; i <= a; i += 2) {
		if (num % i == 0)
			return false;
	}
	return true;
}

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

	int Q;
	cin >> Q;
	VI A;
	VI L(Q);
	VI R(Q);
	for(int i=3;i<=100000;i+=2) {
		if (sosuu(i) && sosuu((i + 1) / 2)) {
			A.push_back(i);
		}
	}
	int sum[100001] = { 0 };
	int j = 0;
	bool F = true;
	eFOR(i, 1, 100000) {
		sum[i] = sum[i - 1];
		if (A[j] == i && F) {
			sum[i]++;
			j++;
		}
		if (j == A.size())F = false;
	}
	
	REP(i, Q) {
		int a, b;
		cin >> a >> b;
		cout << sum[b] - sum[a-1] << endl;		
	}
	return 0;
}



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

hantei = True
condition = [None] * (N+1)
condition[0] = 0
S = []
for s, c in data:
    if (condition[s] is None) or (condition[s] == c):
        condition[s] = c
        S.append(s)
    else:
        break
else:
    hantei = False

if (N != 1 and condition[1] == 0) or hantei:
    print(-1)
else:
    if None in condition:
        temp = list(set(range(1, N+1)) - set(S))
        for t in temp:
            if (N == 1) or (t != 1):
                condition[t] = 0
            else:
                condition[t] = 1
    condition = map(str, condition[1:])
    print("".join(condition))


Measured memory_bytes: 3064
#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;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
ll numLen(ll k) 
{  
    ll num=0;  
    for (int i=1; i<=k; i++) { 
        num = ((num*10)+1)%k; 
        if (num==0) {
            return i; 
        }
    }
    return -1; 
} 


int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll k;
    cin>>k;
    if((k%2==0) || (k%5==0)){
        cout<<-1;
    }
    else{
        if(k%7==0){
            k=k/7;
        }
        cout<<numLen(k);
    }
    return 0;
}


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

int N, K;
int P[1100];

int main(void){

    cin >> N >> K; 
    for (int i = 0;i < N;i++) cin >> P[i];

    sort(P,P+N);
    int total = 0;

    for (int i = 0; i < K;i++) total += P[i];

    cout << total << endl;

    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
typedef long long ll;
#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7;
using namespace std;
ll t;
ll arr[300005][2];


int main()
{
    ll a,b,c,d,e,f,g,i,j;
    cin>>t;
    string s;
    cin>>s;
    f=N;
    for(i=1;i<=s.size();i++)
    {
        if(s[i-1]=='W')arr[i][0]++;
        else arr[i][1]++;
        arr[i][0]+=arr[i-1][0];
        arr[i][1]+=arr[i-1][1];
    }
    for(i=1;i<=t;i++)
    {
        if(i==1)b=arr[t][1];
        else if(i==t)b=arr[t-1][0];
        else
        {
            b=arr[i-1][0];
            b=b+(arr[t][1]-arr[i][1]);
        }
        f=min(f,b);
    }
    if(f==1e9+7)f=0;
    cout<<f<<endl;
    return 0;
}


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

int main()
{
	int N;
	cin >> N;
	int maxDiv = 0;
	int ans=1;
	for (int i = 1; i <= N; i++)
	{
		int k = 0;
		int tmp = i;
		while (tmp % 2 == 0 && tmp!=0)
		{
			tmp /= 2;
			k++;
		}
		if (maxDiv<k)
		{
			maxDiv = k;
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, m;
	cin >> n >> m;
	cout << (n - 1) * (m - 1) << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		
		//String s=sc.next();
		int n=sc.nextInt();
		String w[]=new String[n];
		String ans="Yes";
		for (int i = 0; i < n; i++) {
			String x=sc.next();
			if(i!=0) {
				int l=w[i-1].length();
			
				if(w[i-1].charAt(l-1)!=x.charAt(0)||Arrays.asList(w).contains(x)) {
					ans="No";
				}
				
			}
			
			w[i]=x;
		}
		System.out.println(ans);
		
		
	}	
	
	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}


Measured memory_bytes: 23252
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int n,N[100],i;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>N[i];
		}
	for(i=n-1;i>0;i--){
		cout<<N[i]<<" ";
		}
		cout<<N[0]<<endl;
		
		return 0; 
		}

Measured memory_bytes: 1160