akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
typedef long long ll;
typedef std::vector<int> VI;
typedef std::pair<int, int> PII;

using namespace std;

int main()
{
  int N;
  cin >> N;
  int max1 = 1;
  int max2 = 0;
  vector<int> A(N);
  REP(i,N)
  {
    cin >> A[i];
    if (A[i] >= max1) {
      max2 = max1;
      max1 = A[i];
    } else if (A[i] >= max2)
    {
      max2 = A[i];
    }
  }
  REP(i, N)
  {
    if (A[i] == max1) cout << max2 << endl;
    else cout << max1 << endl;
  }
  return 0;
}


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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  
  if(s.length() <= n) cout << s << endl;
  
  else{
  	for(int i = 0; i < n; i++) cout << s[i];
  
  	cout << "..." << endl;
  }
}

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

int main() {
  string a, b;
  cin >> a >> b;
  
  if (a.size() > b.size()){
    cout << "GREATER" << endl;
  } else if ( a.size() < b.size()){
    cout << "LESS" << endl;
  } else {
    bool eq = true;
    for(int i=0; i<a.size(); i++){
      if ((int)a.at(i) > (int)b.at(i)){
        cout << "GREATER" << endl;
        eq = false;
        break;
      } else if ((int)a.at(i) < (int)b.at(i)){
        cout << "LESS" << endl;
        eq = false;
        break;
      }
    } 
    if (eq) cout << "EQUAL" << endl;
  }
                      
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
cur = 0
ans = 0

for i in range(1, N+1):
    if cur >= N:
        break
    while cur < N and a[cur] != i:
        cur += 1
        ans += 1
    cur += 1
print(ans if N != ans else -1)

Measured memory_bytes: 26140
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
int main(){
int  aa;
	vector<int> a;
	int m=0;
	int mm=0;
	int n=0;
	int c=0;
	int k=0;
	scanf("%d %d", &n, &k);
	scanf("%d", &aa);
a.push_back(aa);
	m = a[0];
	for (int i = 1; i < n; i++){
		scanf("%d", &aa);
                a.push_back(aa);
		if (a[i]<m){
			m = a[i];
		}
		if (a[i] - m>mm){
			mm = a[i] - m;
			c = 0;
		}
		if (a[i] - m == mm)c++;
	}
	printf("%d", c);
	return 0;
}

Measured memory_bytes: 892
from collections import deque


def main():
    h, w = map(int, input().split())
    maze = [list(input()) for _ in range(h)]

    white_count = 0
    for r in range(h):
        for c in range(w):
            if maze[r][c] == ".":
                white_count += 1

    q = deque()
    q.append((0, 0))
    dist = [[-1 for _ in range(w)] for _ in range(h)]
    dist[0][0] = 0

    while q:
        r, c = q.popleft()
        for dr, dc in ((-1, 0), (1, 0), (0, -1), (0, 1)):
            nr = r + dr
            nc = c + dc

            if not (0 <= nr < h and 0 <= nc < w):
                continue

            if maze[nr][nc] == "#":
                continue

            if dist[nr][nc] == -1:
                dist[nr][nc] = dist[r][c] + 1
                q.append((nr, nc))

    if dist[h - 1][w - 1] == -1:
        print(-1)
    else:
        print(white_count - dist[h - 1][w - 1] - 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 74020
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Postdocs solver = new Postdocs();
        solver.solve(1, in, out);
        out.close();
    }

    static class Postdocs {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] T = in.next().toCharArray();
            for (char c : T) {
                if (c == '?') {
                    out.print('D');
                } else {
                    out.print(c);
                }
            }
            out.println();
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 36960
#include<bits/stdc++.h>
using namespace std;
#define maxn 10010
#define maxp 40000
vector<int> pp;
int notp[maxp];
int n,a[maxn];
void pre()
{
        for(int i=2;i<maxp;i++)
        {
                if(!notp[i])notp[i]=i,pp.push_back(i);
                for(int j=0;j<(int)pp.size() && 1ll*i*pp[j]<maxn;j++)
                {
                        notp[i*pp[j]]=pp[j];
                        if(i%pp[j]==0)break ;
                }
        }
//      for(int i=2;i<50;i++)printf("%d: %d\n",i,notp[i]);
}
vector<int> ans;
int cnt[maxn];
int main()
{
        pre();
        scanf("%d",&n);
        for(int i=n;i>=0;i--)scanf("%d",&a[i]);
        int g=0;
        for(int i=0;i<=n;i++)g=__gcd(g,a[i]);
        for(int i=0;i<=n;i++)a[i]/=g;
        g=abs(g);
        for(int i=0;i<(int)pp.size() && g>1;i++)
        {
                if(g%pp[i]==0)
                {
                        ans.push_back(pp[i]);
                        while(g%pp[i]==0)g/=pp[i];
                }
        }
        if(g>1)ans.push_back(g);
                for(int p : pp)
                {
                        if(p-1>n)break ;
//                      printf("p = %d\n",p);
                        if(a[0]%p!=0)continue ;
                                memset(cnt,0,sizeof(cnt));
                                for(int i=0;i<=n;i++)
                                        (cnt[i%(p-1)]+=(a[i]%p+p)%p)%=p;
                                bool flag=1;
                                for(int i=0;i<p-1;i++)
                                        if(cnt[i]%p!=0){flag=0;break;}
                                if(flag)ans.push_back(p);
                }
        sort(ans.begin(),ans.end());
        ans.resize(unique(ans.begin(),ans.end())-ans.begin());
        for(int p : ans)printf("%d ",p);puts("");
        return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int n, q;
ll sum[200000];
vector<int> edges[200000];

void dfs(int i, int p){
    for(int j : edges[i]){
        if(j != p){
            sum[j] += sum[i];
            dfs(j, i);
        }
    }
}

int main(){
    cin >> n >> q;
    int a, b;
    rep(i, n-1){
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }
    int p, x;
    rep(i, q){
        cin >> p >> x;
        sum[p-1] += x;
    }
    dfs(0, -1);
    rep(i, n){
        cout << sum[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 24320
#include<stdio.h>
int selectionSort(int A[], int N){
  int i,j,sw=0,minj,t;
  for(i = 0; i < N-1;i++){
    minj = i;
    for(j = i; j < N;j++){
      if(A[j] < A[minj])minj = j;
    }
    t = A[i]; A[i] = A[minj]; A[minj] = t;
    if(i != minj)sw++;
  }
  return sw;
}
int main(){
  int A[100],N,i,sw;

  scanf("%d",&N);
  for(i = 0;i < N;i++)scanf("%d",&A[i]);

  sw = selectionSort(A,N);
  for(i = 0; i < N; i++){
    if(i > 0 )printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",sw);
  return 0;
}



Measured memory_bytes: 2128
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
long long x;
int main(){
    cin>>x;
    long long ans=x/11;
    x=x-11*ans;
    ans=ans*2;
    if(x==0){
    }else if(x<=6){
       ans++;
    }else{
       ans+=2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define mod 1000000007
using namespace std;
long long dp[410][410];
long long mi[410][410];//i^j前缀和
int a[410],b[410];
int main()
{
	int n,c;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++)
	{
		mi[i][0]=1;
		for(int j=1;j<=c;j++)mi[i][j]=mi[i][j-1]*i%mod;
	}
	for(int i=1;i<=400;i++)for(int j=0;j<=c;j++)mi[i][j]=mi[i][j]+mi[i-1][j];
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	for(int j=0;j<=c;j++)
	for(int k=0;k<=j;k++)
	dp[i][j]=(dp[i][j]+dp[i-1][j-k]*((mi[b[i]][k]-mi[a[i]-1][k])%mod+mod)%mod)%mod;
	printf("%lld\n",dp[n][c]);return 0;
}
//dp[i][j]表示前i个人分j个苹果的方案的累加和
//dp[i][j]=dp[i-1][j-k]*(a[i]^k+...+b[i]^k)

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define rrep(i,n) for (ll i = (n)-1; i >=0; --i)
#define ALL(a) a.begin(),a.end()
#define pb push_back
#define dame { puts("-1"); return 0;}
#define show(x) cerr<<#x<<" = "<<x<<endl;

using namespace std;
using ll = long long;
using ld = long double;
using pl = pair<ll, ll>;

typedef vector<ll> vl;
typedef vector<pl> vp;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const ll mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);


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

  vector<ll> a(n+1);
  ll S = 0;
  rep(i, n+1) {
    cin >> a[i];
    S += a[i];
  }

  if(a[0]>1 || (a[0]==1 && n>1)){
    cout << -1 << endl;
    return 0;
  }
  ll node = 1;
  ll ans = 0;
  rep(i, n){
    show(ans);
    show(node);
    if(node<=0){
      cout << -1 << endl;
      return 0;
    }
    ans += node;
    node -= a[i];
    S -= a[i];
    node = min(S, node*2);
  }
  if(S>node){
    cout << -1 << endl;
    return 0;
  }
  ans += node;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8816
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] g = new int[3][3];
        for (int i = 0; i < 3; i++) {
            g[i][0] = sc.nextInt();
            g[i][1] = sc.nextInt();
            g[i][2] = sc.nextInt();
        }
        boolean ans = true;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                if(g[i][j] - g[i+1][j] != g[i][j+1] - g[i+1][j+1]){
                    ans = false;
                    break;
                }
                if(g[i][j] - g[i][j+1] != g[i+1][j] - g[i+1][j+1]){
                    ans = false;
                    break;
                }
            }
        }

        if(ans) System.out.println("Yes");
        else System.out.println("No");
        sc.close();
    }

}


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

int main() {
	string s;
	cin >> s;
	vector<char>a;
	vector<int>xs = { 0 };
	for (int i = 0; i < s.length(); i++) {
		if (s.at(i) != 'x') {
			a.push_back(s.at(i));
			xs.push_back(0);
		}
		else xs.at(xs.size() - 1)++;
	}
	for (int i = 0; i < a.size() / 2; i++) {
		if (a.at(i) != a.at(a.size() - 1 - i)) {
			cout << -1 << endl;
			return 0;
		}
	}
	ll ans = 0;
	for (int i = 0; i < xs.size() / 2; i++) {
		ans += abs(xs.at(i) - xs.at(xs.size() - 1 - i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1020
#include<iostream>
#include<cstdio>
#include<vector>
#include<complex>
#include<algorithm>
#define P complex<double>
using namespace std;

bool cmp_p(const P& a, const P& b)
{
  return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
}

double det(P a, P b)
{
  return a.real() * b.imag() - b.real() * a.imag();
}

vector<P> graham_scan(P* ps, int n)
{
  sort(ps, ps + n, cmp_p);
  int k = 0;
  vector<P> qs(n * 2);
  for(int i = 0; i < n; i++)
  {  
    while(k > 1 && det(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0)
      k--;
    qs[k++] = ps[i];
  }
  for(int i = n - 2, t = k; i >= 0; i--)
  {  
    while(k > t && det(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0)
      k--;
    qs[k++] = ps[i];
  }
  qs.resize(k - 1);
  return qs;
}

P p[4];
double xa, ya, xb, yb, xc, yc, xd, yd;
int main()
{
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != -1)
  {
    p[0] = P(xa, ya);
    p[1] = P(xb, yb);
    p[2] = P(xc, yc);
    p[3] = P(xd, yd);
    cout << (graham_scan(p, 4).size() == 4 ? "YES" : "NO") << endl;
  }
}

Measured memory_bytes: 1228
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll N;
    cin >> N;

    if (N % 2 == 0) cout << N << endl;
    else cout << ll(2) * N << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
x1, y1, x2, y2 = [int(x) for x in input().split()]
x_ = x2 - x1
y_ = y2 - y1
x3 = x1 - y_
y3 = y1 + x_
x4 = x3 + x_
y4 = y3 + y_
print(* [x4, y4, x3, y3])

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

int main() {
  string s;
  cin >> s;
  string ans = "Yes";
  for (int i = 0; i < s.size(); i += 2) {
    char x = s[i];
    if (x == 'L') {
      ans = "No";
      break;
    }
  }
  for (int i = 1; i < s.size(); i += 2) {
    char y = s[i];
    if ( y == 'R') {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
s = list(input())
K = int(input())

N = len(s)

alphabet = "abcdefghijklmnopqrstuvwxyz"

def search(k, start_dict):
    for chara in alphabet:
        if chara in start_dict:
            k -= 1
            if k == 0:
                return True, chara
            start_list = start_dict[chara]
            new_start_dict = {}
            for start in start_list:
                index = start + 1
                if index == N:
                    continue
                if s[start+1] in new_start_dict:
                    new_start_dict[s[index]].append(index)
                else:
                    new_start_dict[s[index]] = [index]
            has_found, ret = search(k, new_start_dict)
            if has_found:
                return True, chara + ret
            else:
                k = ret
    return False, k

start_dict = {}
for idx, chara in enumerate(s):
    if chara in start_dict:
        start_dict[chara].append(idx)
    else:
        start_dict[chara] = [idx]
_, ans = search(K, start_dict)
print(ans)


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

vi memo(200005, -1);

int solve(int x) {
	if (memo[x] == -1) {
		memo[x] = 1 + solve(x % __builtin_popcount(x));
	}
	return memo[x];
}

int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	memo[0] = 0;
	int n;
	string s;
	cin >> n >> s;
	int x1 = 0, x2 = 0, pop = 0;
	each(c, s) pop += c == '1';
	each(c, s) {
		x1 <<= 1;
		x2 <<= 1;
		if (c == '1') {
			x1++;
			x2++;
		}
		if (pop <= 1) x1 = 0;
		else if (x1 >= pop - 1) x1 %= pop - 1;
		if (x2 >= pop + 1) x2 %= pop + 1;
	}
	vi y(n);
	vb zero(n, false);
	for (int i = n - 1, b1 = 1, b2 = 1;i >= 0;i--, b1 <<= 1, b2 <<= 1) {
		if (pop <= 1) b1 = 0;
		else if (b1 >= pop - 1) b1 %= pop - 1;
		if (b2 >= pop + 1) b2 %= pop + 1;
		if (s[i] == '1') {
			if (pop <= 1) y[i] = 0, zero[i] = true;
			else y[i] = (x1 + pop - 1 - b1) % (pop - 1);
		}
		else y[i] = (x2 + b2) % (pop + 1);
	}
	loop(n) cout << (zero[i] ? 0 : 1 + solve(y[i])) << endl;
	return 0;
}



Measured memory_bytes: 5180
#include <stdio.h>

int main(void)
{
    int A, B, X;
    int na, nb;

    scanf("%d%d%d", &A, &B, &X);
    
    if (A > B * 2){     // B2本のほうが安い
        nb = X / 500;
        if (X % 500 != 0){
            nb++;
        }
        
        printf("%d\n", nb * B);
    }
    else if (A <= B){
        na = X / 1000;
        if (X % 1000 != 0){
            na++;
        }
        printf("%d\n", na * A);
    }
    else {
        na = X / 1000;
        
        if (X % 1000 != 0){
            if (X % 1000 <= 500){
                nb = 1;
            }
            else {
                nb = 0;
                na++;
            }
        }
        
        printf("%d\n", na * A + nb * B);
    }
    
    return (0);
}



Measured memory_bytes: 2104
#include<iostream>
#include<map>

using namespace std;
typedef pair<int,pair<int,pair<int,int> > > PP;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		int id, Univ, AC, WA;
		
		map<PP,int> m;
		for(int i = 0; i < n; ++i)
		{
			cin >> id >> Univ >> AC >> WA;
			m[make_pair(-AC, make_pair(WA, make_pair(id, Univ)))] = id;
		}
		int count = 0, u[1001] = {};
		for(map<PP,int>::iterator it = m.begin(); it != m.end(); ++it)
		{
			int j = it->first.second.second.second;
			bool flag = false;
			if(count < 10 && u[j] < 3 || count < 20 && u[j] < 2 || count < 26 && !u[j])
			{
				flag = true;
			}
			if(flag)
			{
				++count, ++u[j];
				cout << it->second << endl;
			}
		}
	}
}

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

Measured memory_bytes: 0
using System;
class Program{
	static void Main(){
		string s="0"+Console.ReadLine();
		int a=-1,b=-1;
		for(int i=2;i<s.Length;i++){
			if(s[i-1]==s[i]){a=i-1;b=i;break;}
			else if(s[i-2]==s[i]){a=i-2;b=i;break;}
		}
		Console.WriteLine("{0} {1}",a,b);
	}
}

Measured memory_bytes: 13536
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
typedef long long ll;
inline void Fail(){printf("0");exit(0);}

const int maxn=100005;
int n;
int a[maxn];
ll ans;
ll sum[maxn],sum2[maxn];
char c[2];
 
int main(){
	scanf("%d",&n);
	int op=1;
	rep(i,n){
		scanf("%d",&a[i]);
		a[i]*=op;
		if(i!=n-1){
			scanf("%s",c);
			if(c[0]=='-')op=-1;
			else op=1;
		}
	}
	for(int i=n-1;i>=0;i--)sum[i]=sum[i+1]+abs(a[i]);
	for(int i=n-1;i>=0;i--){
		if(a[i]<0)sum2[i]=0;
		else sum2[i]=sum2[i+1]+a[i];
	}
	ll cur=0;
	rep(i,n){
		cur+=a[i];
		if(a[i]<0)ans=max(ans,cur+sum[i+1]-2*sum2[i+1]);
	}
	ans=max(ans,cur);
	printf("%lld",ans);
	return 0;
}

/*
Input:
-----------------
Output:
*/

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

int main() {
    ll H; cin >> H;
    ll cnt = 1;
    ll ans = 0;
    while(H > 0){
        H /= 2;
        ans += cnt;
        cnt *= 2;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 200500;

ll ans;
int n, a[N], cnt[20];

inline bool bad() {
	for (int i = 0; i < 20; i++)
		if (cnt[i] > 1)
			return 1;
	return 0;
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	cin >> n;

	for (int i = 1, ptr = 1; i <= n; i++) {
		cin >> a[i];
		for (int j = 0; j < 20; j++) {
			if (a[i] >> j & 1)
				cnt[j]++;
		}
		while (bad()) {
			for (int j = 0; j < 20; j++)
				if (a[ptr] >> j & 1)
					cnt[j]--;
			ptr++;
		}
		ans += (i - ptr + 1);
	}

	cout << ans;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n = II()
    print(n**2)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if (k<=a)cout <<k;
  else if (k>a && k<=a+b) cout << a;
  else if (k>a+b && k<=a+b+c)cout << a-(k-a-b);
  else cout << a-c;
}

Measured memory_bytes: 3636
defmodule Main do
  def main do
  	alpha = IO.gets("") |> String.trim()
    
    cond do
    	upcase(alpha) ->
        	'A'
        true ->
        	'a'
    end
    |> IO.puts
  end
  
  defp upcase(x), do: String.upcase(x) == x
end

Measured memory_bytes: 31184
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
const int inf = 1e18;
void build(vector<vector<int> >&st,int idx,int start,int end,string &a){
    
    if(start > end){
        return;
    }
    if(start==end){
        int x = a[start] - 'a';
        st[idx][x] = 1; 
        return;
    }
    int mid = (start+end)/2;
    build(st,2*idx,start,mid,a);
    build(st,2*idx+1,mid+1,end,a);
    for(int i=0;i<26;i++){
        st[idx][i] = st[2*idx][i] + st[2*idx+1][i];
    }
}
vector<int> query(vector<vector<int> >&st,int qs,int qe,int start,int end,int idx){
    
    if(qe<start||qs>end){
        return vector<int>(26,0);
    }

    if(start>=qs&&end<=qe){
        return st[idx];
    }
    int mid = (start+end)/2;

    vector<int> l = query(st,qs,qe,start,mid,2*idx);

    vector<int> r = query(st,qs,qe,mid+1,end,2*idx+1);
    vector<int>res(26);
    for(int i=0;i<26;i++){
        res[i] = l[i] + r[i];
    }
    return res;
}
void update(vector<vector<int> >&st,int idx,int start,int end,int x,bool flag,int xx,int xy){

    if(x<start||x>end){
        return;
    }
    if(start==end){
        if(flag){
            if(xx==xy){
                return;
            }
            st[idx][xx] = 0;
            st[idx][xy] = 1;
        }else{
            
        }
        return;
    }
    int mid = (start+end)/2;
    update(st,2*idx,start,mid,x,flag,xx,xy);
    update(st,2*idx+1,mid+1,end,x,flag,xx,xy);
    for(int i=0;i<26;i++){
        st[idx][i] = st[2*idx][i] + st[2*idx+1][i];
    }
    return;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    string a;
    cin>>a;
    vector<vector<int>>st(4*n,vector<int>(26,0));
    build(st,1,0,n-1,a);
    int t;
    cin>>t;
    while(t--){
        int x;
        cin>>x;
        if(x==1){
            int pos;
            cin>>pos;
            char c;
            cin>>c;
            int xx = a[pos-1] - 'a';
            int xy = c - 'a';
            bool flag = true;
            if(a[pos-1]==c){
                flag = false;
            }else{
                a[pos-1] = c;
            }
            update(st,1,0,n-1,pos-1,flag,xx,xy);
            xx = c - 'a';
        }else{
            int l,r;
            cin>>l>>r;
            vector<int>ans = query(st,l-1,r-1,0,n-1,1);
            int c = 0;
            for(int i=0;i<ans.size();i++){
                if(ans[i]){
                    c++;
                }
            }
            cout<<c<<endl;
        }
        
    }
    return 0;
    
}

Measured memory_bytes: 485176
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_12_C: Single Source Shortest Path II

#include <algorithm>
#include <cstdio>
#include <queue>
#include <utility>
#include <vector>

using uint = unsigned int;

class Graph {
  using vc_t = std::pair<uint, uint>;
  std::vector<std::vector<vc_t>> g_;

public:
  Graph(const uint n) { g_.resize(n); }

  void push_to(const uint u, const uint v, const uint c)
  {
    g_[u].push_back(std::make_pair(v, c));
  }

  void dijkstra(uint* dist)
  {
    auto n = g_.size();
    const uint INFINIT = 100000*(n-1)+1;
    std::fill_n(dist, n, INFINIT);
    auto cmp = [](vc_t left, vc_t right) { return left.second > right.second; };
    std::priority_queue<vc_t, std::vector<vc_t>, decltype(cmp)> q(cmp);
    
    q.push(vc_t(0, 0));
    dist[0] = 0u;
    while (!q.empty()) {
      auto bvc = q.top();
      q.pop();
      auto v = bvc.first, c = bvc.second;
      if (dist[v] < c) {
        continue;
      }
      for (auto vc : g_[v]) {
        auto nv = vc.first, nc = vc.second+c;
        if (dist[nv] < nc) {
          continue;
        }
        dist[nv] = nc;
        q.push(std::make_pair(nv, nc));
      }
    }
  }
};

int main()
{
  uint n;
  std::scanf("%u", &n);

  Graph g(n);

  uint u, k, v, c;
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%u %u", &u, &k);
    for (auto j = 0u; j < k; ++j) {
      std::scanf("%u %u", &v, &c);
      g.push_to(u, v, c);
    }
  }

  uint dist[n];
  g.dijkstra(dist);
  for (auto i = 0u; i < n; ++i) {
    std::printf("%u %u\n", i, dist[i]);
  }
}

// eof

Measured memory_bytes: 7348
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  cin >>a>>b;
  if(a<b){
    cout<<"a < b"<<'\n';
  }else if(a>b){
    cout<<"a > b"<<'\n';
  }else if(a==b){
    cout<<"a == b"<<'\n';
  }
  return(0);
}



Measured memory_bytes: 3128
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    A = readInts()
    print(sum(A) - len(A))



if __name__ == '__main__':
  main()


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

#define ll long long int
#define mp make_pair
#define pb push_back
using namespace std;

int main() {
    int n,k;
    cin >> n>>k;
    vector<ll> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    vector<ll> left , right;
    int i ;
    for (i = 0; i < n; ++i) {
        if(v[i] <= 0){
            left.push_back(abs(v[i]));
        }
        else{
            break;
        }
    }
    for (; i < n; ++i) {
        right.push_back(abs(v[i]));
    }
    ll ans= 100000000000000000 ;
    int n1 = left.size();
    int n2 = right.size();
    if(k <= n1){
        ans = min(ans , left[n1 - k]);
    }
    if(k <= n2){
        ans = min(ans , right[k-1]);
    }
    for (int j = 1; j <= k-1 ; ++j) {
        if( (k - j ) <= n2 && j <= n1){
            ans = min(ans , min(2*left[n1 - j] + right[k-j-1] ,left[n1 - j] + 2*right[k-j-1]));
        }
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 2424
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
typedef vector<int> vi;
//const int MAX=;

int main(){
	int N,K;
	cin>>N>>K;
	if((N+1)/2>=K){
		cout<<"YES";
	}
	else cout<<"NO";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N,M;
vector<int>visits;
vector<int>G[1000];
int Count[1000];
int used[1000];
int rev[1000];
bool dfs(int u,int from)
{
	if(Count[u])return false;
	if(u==from)return true;
	visits.push_back(u);
	bool flag=false;
	for(int v:G[u])
	{
		Count[v]++;
		flag|=used[v]==1;
	}
	if(!flag)
	{
		used[u]=1;
		for(int v:G[u])
		{
			if(used[v]||rev[v]<rev[from])continue;
			Count[v]--;
			if(dfs(v,from))return true;
			Count[v]++;
		}
	}
	used[u]=2;
	for(int v:G[u])Count[v]--;
	visits.pop_back();
	return false;
}
main()
{
	cin>>N>>M;
	vector<int>id(N);
	for(int i=0;i<N;i++)id[i]=i;
	for(int i=0;i<M;i++)
	{
		int u,v;cin>>u>>v;
		u--,v--;
		G[u].push_back(v);
	}
	sort(id.begin(),id.end(),[](int a,int b){return G[a].size()>G[b].size();});
	for(int i=0;i<N;i++)rev[id[i]]=i;
	for(int ii=0;ii<N;ii++)
	{
		int i=id[ii];
		for(int j=0;j<N;j++)used[j]=0;
		for(int v:G[i])Count[v]++;
		visits.push_back(i);
		for(int v:G[i])
		{
			Count[v]--;
			if(dfs(v,i))
			{
				cout<<visits.size()<<endl;
				for(int id:visits)cout<<id+1<<endl;
				return 0;
			}
			Count[v]++;
		}
		for(int v:G[i])Count[v]--;
		visits.pop_back();
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int f(long long int n,long long int m){
	int i=0;
	while(n!=0||m!=0){
		n/=10;
		m/=10;
		i++;
	}
	return i;
}

	
int main(){
	long long int n;
	cin>>n;
	long long int a=1,b,min=1e9,k;
	while(a*a<=n){
		if(n%a==0){
			b=n/a;
			k=f(a,b);
			if(min>k)min=k;
		}
		a++;
	}
	cout<<min<<endl;



	return 0;
}

Measured memory_bytes: 256
X, Y, Z, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)
tot = []
for i in range(X):
   for j in range(Y):
      for k in range(Z):
         if((i+1)*(j+1)*(k+1) <= K): tot.append(a[i] + b[j] + c[k])
         else: break
tot.sort(reverse = True)
for i in range(K):print(tot[i])


Measured memory_bytes: 8708
#include <iostream>
using namespace std;
const int Max = 10000000;
bool prime[Max];
int main() {
    int in;
    for(int i=0; i<Max; i++) prime[i] = true;
    prime[1] = false;
    for(int i=2; i<Max; i++) {
        if(prime[i]) {
            for(int s=i*2; s<=Max; s+=i) prime[s] = false;
        }
    }
    while(cin >> in) {
        int cnt = 0;
        for(int i=1; i<=in; i++) {
            if(prime[i]) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 10924
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int ans = 0;
	string S;
	cin >> S;

	char ch = S[0];

	for (int i = 1;i < S.size();i++)
	{
		if (ch != S[i])
		{
			ans++;
			ch = S[i];
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ull unsigned long long
#define db double
#define vi vector<ll>
#define vvi vector<vector<int> >
#define vvii vector<vector<pii> >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll> >
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define pb push_back
#define pf push_front
#define F first 
#define S second 
#define mp make_pair
#define all(v) v.begin(),v.end()

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}



#define deb1(a) cout<<#a<<"=*"<<a<<endl;
#define deb2(a) cout<<#a<<"=@"<<a<<endl;
#define deb3(a) cout<<#a<<"=#"<<a<<endl;
#define deb4(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;
#define deb5(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;


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


ll mod=1000000007;
ll vis[212345]={0};
vvi v(212345);
ll d[212345]={0};


ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}





int main()
{
speed
ll x,k,d;
cin>>x>>k>>d;
ll f=x/(abs(x));
if(f==0)
{
	if((k%2)) cout<<d<<endl;
	else cout<<"0\n";
}
else
{
	ll z=(abs(x)/d);
//	deb1(z);
	if(z>k)
	{
		cout<<(abs(x)-k*d)<<endl;
	}
	else if(z==k)
	{
		cout<<(abs(x)-z*d)<<endl;
	}
	else
	{
		
	ll f1=(abs(x)%d);
	
	ll f2=d-f1;
	if(z%2==k%2)
	cout<<f1<<endl;
	else cout<<f2<<endl;
	}
}

}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;

int main(){
    double n,m,d;
    cin >> n >> m >> d;
    double ans = (m-1) * (n-d) / (n*n);
    if(d) ans *= 2;
    printf("%.10lf\n", ans);
}


Measured memory_bytes: 256
n = int(input())
s = input()
k = int(input())

str_list = list(s)
x = str_list[k-1]
for i in range(len(s)):
    if str_list[i] != x:
        str_list[i] = "*"
str_changed = "".join(str_list)
print(str_changed)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cassert>
using namespace std;

typedef vector<int> VI;

#define REP(i, n) for (int i=0;i<n;++i)
#define FOR(i, a, b) for (int i=a;i<b;++i)
#define REP_1(i, n) for (int i=1;i<=n;++i)
#define ALL(A) A.begin(), A.end()
#define PB push_back


const int N = 109, M = 5040;
int a[105], d[105], pos[105];
int n, ans; int ne[M][10]; int dp[105][M];
vector<VI> P; VI p;

int main(){


#define conds P

    cin >> n; for(int i = 0;i < n;i++)cin >> d[i];
    for(int i = 0;i < n;i++) cin >> a[i];

    VI p; REP(i, 7) p.PB(i);
    do P.PB(p); while(next_permutation(ALL(p)));

    REP(i, M){
        vector<int> tmp1, tmp2;

       // REP(j, 7) cout << P[i][j] << " "; puts("");
       //.. 01234 .. 012345

        for(int j = 0;j < 8;j++){
            p = conds[i]; REP(i, 7) if (p[i] >= j) ++p[i];
            FOR(i, 1, 7) if (p[i] >= p[0]) --p[i]; p.erase(p.begin());
            ne[i][j] = lower_bound(ALL(P), p) - P.begin();
        }
    }

    for(int  i = 0;i < n;i++){
        for(int j = 0;j < M;j++){

            for(int k = 0;k < 7;k++)pos[conds[j][k]] = k;
            int res = dp[i][j];

            for(int k = 0;k < 7;k++)
                if(i - 7 + k >= 0 && 7 - k <= d[i])res += a[i];

            for(int k = 0;k < 8;k++){
                dp[i + 1][ne[j][k]] = max(dp[i + 1][ne[j][k]], res);
                ans = max(ans, dp[i + 1][ne[j][k]]);
                if(i - 7 + pos[k] >= 0 && 7 - pos[k] <= d[i])res -= a[i];
                if(i - 7 + pos[k] >= 0 && 7 - pos[k] <= d[i - 7 + pos[k]])res += a[i - 7 + pos[k]];
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

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

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

const ll MOD = 1000000007;

vector<ll> dp1, dp2;

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

    int slen = (int) S.size();
    dp1.resize(slen, 0);
    dp2.resize(slen, 0);

    // The first digit must be 0
    dp1[0] = 1;
    dp2[0] = 2;

    for (int i = 1; i < slen; i++) {
        if (S[i] == '0') {
            dp1[i] = (dp1[i - 1] * 3) % MOD;
            dp2[i] = dp2[i - 1];
        } else {
            dp1[i] = (((dp1[i - 1] * 3) % MOD) + dp2[i - 1]) % MOD;
            dp2[i] = (dp2[i - 1] * 2) % MOD;
        }
        // printf("dp1[%d]: %lld, dp2[%d]: %lld\n", i, dp1[i], i, dp2[i]);
    }

    cout << (dp1[slen - 1] + dp2[slen - 1]) % MOD << endl;

    return 0;
}


Measured memory_bytes: 2048
# -*- coding: utf-8 -*-
# 整数の入力

def get_list():
    return list(map(int, input().split()))

N, M = map(int, input().split())
war = []
for i in range(M):
    war.append(get_list())
war.sort()

cnt = 1
west, east = war[0]
# スペース区切りの整数の入力
for i in range(1, len(war)):
    west_chk, east_chk = war[i]
    if west_chk < east and east <= east_chk:
        pass
    elif east <= west_chk:
        cnt += 1
        east = east_chk
    elif west_chk < east:
        east = east_chk
        
print(cnt)




Measured memory_bytes: 27880
#include<iostream>
using namespace std;
int main(){
  int X,Y; cin >> X >> Y;
  int ans = 0;
  if(X==1) ans += 300000;
  else if(X==2) ans += 200000;
  else if(X==3) ans += 100000;
  if(Y==1) ans += 300000;
  else if(Y==2) ans += 200000;
  else if(Y==3) ans += 100000;
  
  if(X==1 && Y==1) ans += 400000;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(void) {
    ld LLL;
    cin >> LLL;
    double L = LLL/3;
    cout << fixed << setprecision(10) << L*L*L<< endl;
}

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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] dg = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var d = dg[0];
        var g = dg[1];

        int[] p = new int[d];
        int[] c = new int[d];
        for (int i = 0; i < d; i++)
        {
            int[] pc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            p[i] = pc[0];
            c[i] = pc[1];
        }

        //0(false) = 解かない
        //1(true)  = 完全に解く
        //bit探索(bit全探索)
        long ans = long.MaxValue;
        for (int x = 0; x < Math.Pow(2, d); x++)
        {
            var array = new bool[d];

            // 右からk桁目を取り出す
            for (int k = 0; k < d; k++)
            {
                var y = (x >> k) & 1;
                if (y == 1) array[k] = true;
            }

            long tmp = 0;
            long count1 = 0;
            long last = 0;
            for (int k = 0; k < d; k++)
            {
                if (array[k])
                {
                    tmp += (k + 1) * 100 * p[k] + c[k];
                    count1 += p[k];
                }
                else
                {
                    last = k;
                }
            }

            //g以下の場合は中途半端に解く
            long count2 = 0;
            while (tmp < g && count2 < p[last])
            {
                tmp += (last + 1) * 100;
                count2++;
            }

            if (tmp >= g)
            {
                ans = Math.Min(ans, count1 + count2);
            }
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,a[N];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	int cnt=0;
	for (int i=1;i<=n;i++)
		if (a[i]>=i) cnt++;
	int x=a[cnt]-cnt+1,y=1;
	while (a[cnt+y]>=cnt) y++;
	puts(!(x&1)||!(y&1)?"First":"Second");
	return 0;
}

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

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

   vector<string> S(N);
   for (int i = 0; i < N; i++)
      cin >> S.at(i);

   sort(S.begin(), S.end());

   for (int i = 0; i < N; i++)
      cout << S.at(i);
   cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int T;
	int A[100001];
	int minnum=INF;
	int absmax=0;
	int tajudo=0;
	scan(N);scan(T);
	rep(i,N){
		scan(A[i]);
		if(A[i]<minnum){
			minnum=A[i];
		}
		else if(A[i]-minnum>absmax){
			absmax=A[i]-minnum;
			tajudo=1;
		}
		else if(A[i]-minnum==absmax){
			tajudo++;
		}
	}
	prin(tajudo);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

LL dp[100010][2] = {};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int len = S.length();
    dp[0][0] = 1;
    REP(i,len){
        if(S[i] == '1'){
            dp[i+1][0] = (dp[i][0] * 2)%MOD;

            dp[i+1][1] += (dp[i][1] * 3);
            dp[i+1][1] %= MOD;
            dp[i+1][1] += dp[i][0];
            dp[i+1][1] %= MOD;

        }
        else{
            dp[i+1][0] = dp[i][0];

            dp[i+1][1] = dp[i][1] * 3;

            dp[i+1][0] %= MOD;
            dp[i+1][1] %= MOD;
        }
        dump(i+1)
        dump(dp[i+1][0])
        dump(dp[i+1][1])

    }
    cout << (dp[len][0] + dp[len][1]) % MOD << endl;

}

Measured memory_bytes: 2000
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=a-1;i>=b;i--)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.14159265358979323

void Fast_IO() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   #ifndef ONLINE_JUDGE
   freopen("in.txt","r",stdin);
   freopen("out.txt","w",stdout);
   #endif
} 

vector<vector<ll> >vii;

int main(){
   //Fast_IO();
   ll x,y;
   cin>>x>>y;
   cout<<x*y<<endl; 
}


Measured memory_bytes: 3636