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

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int V,E;

int d[100][100];

void warshall_floyd(int n){
  rep(i,0,n)rep(j,0,n)rep(k,0,n){
    if(d[j][k]>d[j][i]+d[i][k])d[j][k]=d[j][i]+d[i][k];
  }
}


signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>V>>E;
    fill_n(*d,10000,INF);
for(int i=0;i<V;i++)d[i][i]=0;
    rep(j,0,E){
        int a,b,c;
        cin>>a>>b>>c;
        d[a][b]=c;
    }
    warshall_floyd(V);
    
    for(int i=0;i<V;i++){
       if(d[i][i]<0){
           cout<<"NEGATIVE CYCLE"<<endl;
           return 0;
       }
   }
   for(int i=0;i<V;i++){
        for(int j=0;j<V;j++){
            cout<<(j?" ":"");
            if(d[i][j]>(1e9)*2)cout<<"INF";
            else cout<<d[i][j];
        }
        cout<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3288
O = list(input())
E = list(input())
if len(O) == len(E) :
    pas = ['8'] * (2 * len(O))
    for i in range(len(O)) :
        pas[2*i] = O[i]
        pas[2*i + 1] = E[i]
    p = ''.join(pas)
    print(p)
else :
    pas = ['0'] * (2 * len(E) + 1)
    for i in range(len(E)) :
        pas[2*i] = O[i]
        pas[2*i +1] = E[i]
    pas[2 * len(E)] = O[-1]
    p = ''.join(pas)
    print(p)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n,q;
  string s;
  cin>>n>>q>>s;
  vector<char>t(q),d(q);
  rep(i,q)cin>>t[i]>>d[i];
  s='?'+s+'?';
  int l=0,r=n+1;
  for(int i=q-1;i>=0;i--){
    if(d[i]=='R'){
      if(s[r-1]==t[i])r--;
      if(s[l]==t[i])l--;
    }
    else{
      if(s[r]==t[i])r++;
      if(s[l+1]==t[i])l++;
    }
  }
  cout<<r-l-1<<endl;
  return(0);
}


Measured memory_bytes: 1156
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    long n, sum=0, a, minabs=(int)1e9, count=0;
    scanf("%ld", &n);
    for (int i=0; i<n; i++) {
        scanf("%ld", &a);
        sum += abs(a);
        if (a < 0)
            count++;
        minabs = min(minabs, abs(a));
    }
    printf("%ld\n", sum - (count%2 ? 2*minabs : 0));
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<cassert>
#include<vector>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int ans[214514];
queue<int>V;
signed main() {
	int n, x; cin >> n >> x;
	if (x == 1 || x == 2 * n - 1) {
		puts("No");
	}
	else {
		puts("Yes");
		if (n == 2) {
			rep(i, 3)cout << i + 1 << endl;
		}
		else {
			if (x == 2) {
				ans[n - 1] = x;
				ans[n - 2] = 3;
				ans[n] = 1;
				ans[n + 1] = 4;
				for (int i = 5; i <= 2 * n - 1; i++)V.push(i);
				rep(i, 2 * n - 1) {
					if (!ans[i]) {
						ans[i] = V.front();
						V.pop();
					}
				}
			}
			else {
				ans[n - 1] = x;
				ans[n - 2] = 1;
				ans[n] = 2 * n - 1;
				ans[n + 1] = 2;
				for (int i = 3; i <= 2 * n; i++) {
					if (i != x)V.push(i);
				}
				rep(i, 2 * n - 1) {
					if (!ans[i]) {
						ans[i] = V.front();
						V.pop();
					}
				}
			}
			rep(i, 2 * n - 1)cout << ans[i] << endl;
		}
	}
}


Measured memory_bytes: 4736
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
typedef long long ll;

int main(void)
{
    int n;
    cin >> n;
    int a[n];
    int b[n];
    REP(i, n)
    {
        cin >> a[i];
        b[i] = a[i];
    }
    long long ans = 0;
    long long tmp = 0;
    long long sum = 0;
    // start with plus
    rep(i, 0, n)
    {
        if (i % 2 == 0)
        {
            // プラス
            sum += a[i];
            if (sum <= 0)
            {
                tmp += abs(sum - 1);
                sum = 1;
            }
        }
        else
        {
            // マイナス
            sum += a[i];
            if (sum >= 0)
            {
                tmp += abs(sum + 1);
                sum = -1;
            }
        }
    }
    ans = tmp;
    tmp = 0;
    sum = 0;
    // start with -
    rep(i, 0, n)
    {
        if (i % 2 != 0)
        {
            // +
            sum += a[i];
            if (sum <= 0)
            {
                tmp += abs(sum - 1);
                sum = 1;
            }
        }
        else
        {
            // -
            sum += a[i];
            if (sum >= 0)
            {
                tmp += abs(sum + 1);
                sum = -1;
            }
        }
    }

    ans = min(ans, tmp);
    cout << ans << endl;
}

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

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		int strN = 1; // 文字列を何行受け取るか
		for (int i = 0; i < strN; i++) {
			line += br.readLine() + " ";
		}
		String[] param = line.split(" ");
		AZ(param);

	}

	static void AZ(String[] param) {

		System.out.println((param[0].lastIndexOf("Z")) - (param[0].indexOf("A")) + 1);
	}
}

Measured memory_bytes: 27476
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x;
    cin >>n>>x;
    vector<int> l(n);
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    int ans=1;
    int p=0;
    for(int i=0;i<n;i++){
        p+=l[i];
        if(p<=x)++ans;
    }
    cout<<ans<<endl;
    return 0;
}

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

signed main() {
    int a, b, k;
    stack<int> vec;
    cin >> a >> b >> k;
    
    for ( int i = 1; i <= min(a, b); i++ ) {
        if ( a % i == 0 && b % i == 0 ) {
            vec.push(i);
        }
    }
    
    for ( int i = 1; i < k; i++ ) {
        vec.pop();
    }
    cout << vec.top() << endl;
    return (0);
}

Measured memory_bytes: 3600
n,*s=map(int,open(0).read().split())
m=0
for i in range(1,n):
    t=0
    for j in range(0,n,i):
        k=n-1-j
        if k<i or k%i<1 and k<=j:break
        t+=s[j]+s[k]
        if t>m:m=t
print(m)

Measured memory_bytes: 14084
//  Suraj Saste

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pi pair<double,ll>
#define in insert
#define fe first
#define se second
#define ms(x,i) memset(x,i,sizeof(x))
#define prec(x) cout<<std::setprecision(x)
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll fpow(ll n, ll k, ll p=mod) {ll r=1; n=n%p; while(k>0){ if(k&1){ r=(r*n)%p; } k=k>>1; n=(n*n)%p; } return r;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 || n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0||n%(i+2)==0)return false;}return true;}

int main()
{
	fast;
	ll n,w;cin>>n>>w;
	ll a[n],b[n];
	vector<ll> dp[105];
	for(ll i=0;i<n;i++)cin>>a[i]>>b[i];
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=w;j++)dp[i].pb(0);
	}
	for(ll i=1;i<=w;i++)
	{
		if(i>=a[0])dp[0][i]=b[0];
		else dp[0][i]=0;
	}
	for(ll i=1;i<n;i++)
	{
		for(ll j=1;j<=w;j++)
		{
			if(j<a[i])dp[i][j]=dp[i-1][j];
			else
			{
				dp[i][j]=b[i]+dp[i-1][j-a[i]];
			    dp[i][j]=max(dp[i][j],dp[i-1][j]);
			}
		}
	}
	// for(ll i=0;i<n;i++)
	// {
	// 	for(ll j=0;j<=w;j++)cout<<dp[i][j]<<" ";
	// 	cout<<"\n";
	// }
	cout<<dp[n-1][w];
	return 0;
}


Measured memory_bytes: 80244
using System;

namespace ABC140
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] A = new int[N];
            int[] B = new int[N];
            int[] C = new int[N];

            string[] input = Console.ReadLine().Split(' ');
            for (int i = 0; i < N; i++)
            {
                A[i] = int.Parse(input[i]);
            }

            input = Console.ReadLine().Split(' ');
            for (int i = 0; i < N; i++)
            {
                B[i] = int.Parse(input[i]);
            }

            input = Console.ReadLine().Split(' ');
            for (int i = 0; i < N - 1; i++)
            {
                C[i] = int.Parse(input[i]);
            }

            int count = B[A[0] - 1];
            for (int i = 1; i < N; i++)
            {
                if (A[i] == A[i - 1] + 1)
                {
                    count += B[A[i] - 1] + C[A[i] - 2];
                }
                else
                {
                    count += B[A[i] - 1];
                }
            }

            Console.WriteLine(count);

        }
    }
}


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

using namespace std;


int main(){
	
	string s,t;
	cin>>s>>t;
	int ans=0;
	for(int i=0;s[i];i++){
		if(s[i]!=t[i]) ans++;
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3916
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const ll mo = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N, M, S, T;
vector<pii> E[100009];
ll D[2][100009], pat[2][100009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>M>>S>>T;
    S--; T--;
    rep(i,M){
        int u,v,c; cin>>u>>v>>c;
        u--; v--;
        E[u].push_back({v,c});
        E[v].push_back({u,c});
    }
    
    priority_queue<pair<ll,int>> P;
    pat[0][S]=pat[1][T]=1;
    rep(i,N) D[0][i]=D[1][i]=1LL<<60;
    D[0][S]=D[1][T]=0;
    P.push({0,S});
    P.push({0,T+100000});
    
    while(P.size()){
        int cur=P.top().second%100000;
        int id=P.top().second/100000;
        ll co=-P.top().first;
        P.pop();
        if(D[id][cur]!=co) continue;
        for(auto& e:E[cur]){
            if(co+e.second<D[id][e.first]){
                pat[id][e.first]=0;
                D[id][e.first]=co+e.second;
                P.push({-D[id][e.first],id*100000+e.first});
            }
            if(co+e.second==D[id][e.first]) (pat[id][e.first]+=pat[id][cur])%=mo;
        }
    }
    
    ll tot=pat[0][T]*pat[0][T]%mo;
    rep(i,N) if(D[0][i]+D[1][i]==D[0][T]){
        if(D[0][i]==D[1][i]){
            tot+=mo-pat[0][i]*pat[0][i]%mo*pat[1][i]%mo*pat[1][i]%mo;
        }
        if(D[0][i]<D[1][i]){
            for(auto& e:E[i]) if(D[0][e.first]+D[1][e.first]==D[0][T]&&D[0][e.first]>D[1][e.first]&&D[0][e.first]==D[0][i]+e.second){
                tot+=mo-pat[0][i]*pat[0][i]%mo*pat[1][e.first]%mo*pat[1][e.first]%mo;
            }
        }
        tot%=mo;
    }
    cout1(tot);
}


Measured memory_bytes: 16496
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static double debt = 100000;

	public static void main(String[] args) throws IOException {

		double hell = debt;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		for (int i = 1; i <= n; i++) {
			hell *= 1.05;
			hell = Math.ceil(hell / 1000) * 1000;
		}

		System.out.println((int) hell);
	}
}

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

int f(int n){
  
  if(n%2==0) return n/2;
  
  return 3*n+1;
}

int main(){
  int s;
  cin >> s;
  
  int a = s;
  
  int index = 2;
  map<int, int> mp;
  while (mp[f(a)]==0){
    mp[a]++;
    a = f(a);
    index++;
  }
  
  cout << index << endl;
  
  return 0;
}

Measured memory_bytes: 256
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	LL n, a, prev = 0, ans = 0;
	cin >> n;
	for (LL i = 0; i < n; ++i) {
		cin >> a;
		if (a < prev) {
			ans += abs(prev - a);
		}
		prev = max(prev, a);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main()
{
    int A, B, C;
    cin>>A>>B>>C;
    if((C>A && C<B) || (A==B && B==C)) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  
  
int calcAngle(double h, double m)  
{  
    // validate the input  
    if (h <0 || m < 0 || h >12 || m > 60)  
        printf("Wrong input");  
  
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
  
    // Calculate the angles moved  
    // by hour and minute hands  
    // with reference to 12:00  
    int hour_angle = 0.5 * (h * 60 + m);  
    int minute_angle = 6 * m;  
  
    // Find the difference between two angles  
    int angle = abs(hour_angle - minute_angle);  
  
    // Return the smaller angle of two possible angles  
    angle = min(360 - angle, angle);  
  
    return angle;  
}  

int main()
{
	fastio
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  if(h==12) h=0;
  if(m==60) m=0;

  double h_angle = 0.5*(h*60  +  m);
  double m_angle = 6*m;

  double angle = abs(h_angle - m_angle);
  angle = min(angle, 360 - angle);

  double ans = (a*a + b*b - 2*a*b*cos(PI*angle/180.0) );
  ans = sqrt(ans);
  cout << fixed << setprecision(16)<< ans;


	return 0;
}






Measured memory_bytes: 4168
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int T = sc.nextInt();
      int C = (int)((T+0.5)/A);
      System.out.println(C*B);
    }
}

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

const int N = 3E3 + 1;
double dp[N][N], a[N], ans;
int main() {
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) scanf("%lf", a + i);
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
                for (int j = 0; j <= i; j++) {
                        if (j) dp[i][j] += dp[i - 1][j - 1] * a[i];
                        dp[i][j] += dp[i - 1][j] * (1 - a[i]);
                }
        }

        for (int i = n / 2 + 1; i <= n; i++) ans += dp[n][i];
        printf("%0.10lf", ans);
}

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

int main() {
	int A,B,K;
  	cin >> A >> B >> K;
  
  	if(B - A + 1 <= 2 * K) {
        for(int i = 0; i < B - A + 1; i++) {
        cout << A + i << endl;
        }
    }else {
		for(int i = 0; i < K; i++) {
            cout << A + i << endl;
        }

        for(int i = K - 1; i >= 0; i--) {
            cout << B - i << endl;
        }
      }
}

Measured memory_bytes: 256
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    # sys.setrecursionlimit(int(pow(10,6)))
    sys.stdin = open("input.txt", "r")
    # sys.stdout = open("../output.txt", "w")
except:
    pass

n=L()[0]
H=L()
dp=[0 for i in range(n)]
dp[1]=abs(H[1]-H[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))
print(dp[-1])



endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")



Measured memory_bytes: 22220
import collections
n = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
c = 0
C = [0 for i in range(n)]
for i in B:
    c += B[i]*(B[i]-1)//2
for i in range(n):
    C[i] = B[A[i]]
for i in C:
    print(c - (i*(i-1)//2) + ((i-1)*(i-2)//2))

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

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

Measured memory_bytes: 1156
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

int main(){
  string s,t;
  cin>>s>>t;
  cout<<t+s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

constexpr long long mod = 1000000007;

int main() {
    int n,h,w;
    cin >> h >> w >> n;
    int r = (n / max(h,w));
    if(n % max(h,w) != 0) r ++;
    cout << r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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;i>=0;i--)
#define MAX 100001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int,int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 1e9;
const ll INF = 1e18;
#define B 100

int dp[151][11][80];
int a[151][11], b[151][11];
int main(){
	int n, m, t, t1, t2;
	while(1){
		scanf("%d%d", &n, &m);
		if(!n)break;
		fill((int*)b, (int*)(b+151), inf);
		for(int i = 2;i <= 150;i++){
			rep(j,11)rep(k,80)dp[i][j][k] = inf;
			rep(j,11)rep(k,80)if(k != m)dp[2][j][k] = 0;
		}
		rrep(i,n){
			scanf("%d", &t);
			rep(j,t){
				scanf("%d%d", &t1, &t2);
				a[i][j] = t1;
				b[i][j] = t2;
			}
		}
		
		int d1, d2;
		for(int i = 2;i <= n;i++){
			for(int j = 0;j <= 10;j++){
				for(int k = 0;k <= m;k++){
					for(int u = 0;u <= 10;u++){
						d1 = abs(a[i][j]-a[i-1][u]);
						t1 = b[i][j]+b[i-1][u];
						d2 = abs(a[i][j]-a[i-2][u]);
						t2 = b[i][j]+b[i-2][u];
						
						if(b[i][j] != inf && b[i-1][u] != inf)
						dp[i][j][k] = min(dp[i][j][k], dp[i-1][u][k]+t1*d1);
						if(k < m && b[i][j] != inf && b[i-2][u] != inf)
						dp[i][j][k] = min(dp[i][j][k], dp[i-2][u][k+1]+t2*d2);
					}
				}
			}
		}
		int ans = inf;
		for(int i = 0;i <= 10;i++)ans = min(ans, dp[n][i][0]);
		for(int i = 0;i <= 10;i++)ans = min(ans, dp[n-1][i][1]);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  
  for(int i=0; i<K; i++){
    int d;
    cin >> d;
    for(int j=0; j<d; j++){
      int A;
      cin >> A;
      a.at(A-1) += 1;
    }
  }
  int count = 0;
  for(int i=0; i<N; i++){
    if(a.at(i) == 0){
      count += 1;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3568
N = int(input())
S1 = input()
S2 = input()

P = 10**9 + 7

if N == 1:
  print(3)
  exit()

if S1[0] == S1[1]:
  rlt = 6
  f = 1
  i = 2
else:
  rlt = 3
  f = 0
  i = 1
  
while i < N-1:
  if f == 0:
    rlt *= 2
    rlt %= P
    if S1[i] != S1[i+1]:
      i += 1
    else:
      f = 1
      i += 2
  else:
    if S1[i] != S1[i+1]:
      f = 0
      i += 1
    else:
      rlt *= 3
      rlt %= P
      i += 2

if i == N-1 and f == 0:
  rlt *= 2
  rlt %= P

print(rlt)

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

int main() {
  
  string S;
  
  cin >> S;
  
  if(S[0] == '0' && S[1] == '0' && S[3] == '0' && S[2] == '0'){
    cout << "NA" << endl;
  }
  
  else if(S[3] == '0' && S[2] == '0'){
    if(S[0] == '1' && S[1] < '3' || S[0] == '0'){
      cout << "MMYY" << endl;
    }
    else{
      cout << "NA" << endl;
    }
  }
   else if(S[1] == '0' && S[0] == '0'){
    if(S[2] == '1' && S[3] < '3' || S[2] == '0'){
      cout << "YYMM" << endl;
    }
    else{
      cout << "NA" << endl;
    }
  }
  else{
    if(S[2] == '1' && S[3] < '3' || S[2] == '0'){
      if(S[0] == '1' && S[1] < '3' || S[0] == '0'){
        cout << "AMBIGUOUS" << endl;
      }
      else{
        cout << "YYMM" << endl;
      }
    }
    else if(S[0] == '1' && S[1] < '3' || S[0] == '0'){
      cout << "MMYY" << endl;
    }
    else{
      cout << "NA" << endl;
    }
    
  }
  
  
}




Measured memory_bytes: 256
using System;
using System.Linq;

namespace AOJ
{
	class Program
	{
		public static void Main(string[] args)
		{
			decimal m = 100000;
			foreach(var i in Enumerable.Range(1, int.Parse(Console.ReadLine())))
			{
				m *= 1.05m;
				m = Math.Ceiling(m / 1000) * 1000;
			}
			Console.WriteLine(m);
		}
	}
}

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

int main(){
  cin.tie(0);
 	ios::sync_with_stdio(false);
  int A, B, C;
  cin >> A >> B >> C;
  int x = 0;
  int coin = 0;
  while(coin < C){
    x++;
    coin = A * x + (x / 7) * B;
  }
  cout << x <<"\n";
  return 0;
}



Measured memory_bytes: 3200
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
# (a, b) := (仕事にかかる時間, 締め切り)

ab = sorted(ab, key = lambda x:x[1])
time = 0
for a, b in ab:
    time += a
    if time <= b:continue
    print('No')
    exit()
print('Yes')

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int count = 0;
    vector< pair<char, int> > ss;
    for(int i=0; i<n; i++){
        if(s[i]!='x'){
            count++;
            ss.push_back(make_pair(s[i], i));
        }
    }
    int ans = 0;
    vector<char> l;
    vector<char> r;

    if(count == 0){
        cout << 0 << endl;
        return 0;
    }
    for(int i=0; i<count/2; i++){
        if(ss[i].first != ss[count-1-i].first){
            cout << -1 << endl;
            return 0;
        }
    }

    int l_index = 0;
    int r_index = n-1;

    for(int i=0; i<n; i++){
        if(l_index >= r_index){
            break;
        }
        if(s[l_index] == s[r_index]){
            l_index++;
            r_index--;
        }else{
            ans++;
            if(s[l_index]=='x'){
                l_index++;
            }else{
                r_index--;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1528
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    
    let answer = ((100 * (N - M)) + (1900 * M)) * Math.pow(2, M);
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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


def main():
    from itertools import accumulate

    n = int(input())
    a = sorted(list(map(int, input().split())))
    sum_a = list(accumulate([0] + a))
    ans = [False for _ in range(n)]
    ans[n - 1] = True

    for i in range(n - 2, -1, -1):
        if a[i + 1] <= 2 * a[i]:
            if ans[i + 1]:
                ans[i] = True
        elif a[i + 1] <= 2 * sum_a[i + 1]:
            if ans[i + 1]:
                ans[i] = True
        else:
            ans[i] = False

    print(sum(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14432
N = gets.to_i
res = 0
h = {}
N.times do |i|
    s = gets.chomp
    s = s.split('').sort.join()
    if h.has_key?(s) then
        res += h[s]
        h[s] += 1
    else
        h[s] = 1
    end

end
puts res

Measured memory_bytes: 18428
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

int main() {
    ll S;
    cin >> S;
    ll a = 1000000000;
    ll d = S / a + (S % a != 0);
    ll b = a * d - S;
    ll c = 1;
    assert(abs(a*d-b*c) == S && 0 <= a && a <= 1000000000 && 0 <= b && b <= 1000000000 && 0 <= c && c <= 1000000000 && 0 <= d && d <= 1000000000);
    cout << "0 0 " << a << " " << b << " " << c << " " << d << endl;
}


Measured memory_bytes: 256
from collections import defaultdict
from bisect import bisect_right
N,K,*A = map(int, open(0).read().split())
a = A[0]
p = 0
ls = []
dic = defaultdict(list)
for i,c in enumerate(A):
  dic[c].append(i)
while True:
  ls.append(p)
  ind = bisect_right(dic[a],p%N)
  if ind==len(dic[a]):
    ind = 0
    p += N
  p = (p//N)*N+dic[a][ind]+1
  if p%N==0:
    M = p//N
    break
  a = A[p%N]
K %= M
X = N*K
I = bisect_right(ls,X)-1
X -= ls[I]
p = ls[I]%N
S = set()
cnt = 0
ans = []
while X:
  if A[p] not in S:
    S.add(A[p])
    ans.append(A[p])
    cnt += 1
  else:
    i = ans.index(A[p])
    ans = ans[:i]
    S = set(ans)
    cnt = i
  X -= 1
  p += 1
  p %= N
print(' '.join(map(str,ans)))    

Measured memory_bytes: 88056
a=input().split()
b=input().split()
N=int(a[0])
X=int(a[1])
Xm=[abs(int(i)-X) for i in b]
def f(x,y):
    if y > x:
        x,y = y,x
    else:
        pass
    while x%y!=0:
        z = x%y
        x = y
        y = z
    return y
if len(Xm) ==1:
    print(Xm[0])
else:
    c = f(Xm[0],Xm[1])
    for i in range(len(Xm)-2):
        c=f(c,Xm[i+2])
    print(c)

Measured memory_bytes: 14224
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){

    ll a,b,c,k;
    cin>>a>>b>>c>>k;

    ll ans = 0;
    ll a1 = min(a,k);
    ans+=a1;
    k-=a1;
    if(k>0){
        ll b1 = min(b,k);
        k-=b1;
        if(k>0){
          
            ll c1 = min(c,k);
            ans+=c1*(-1);
        }

    }
    cout<<ans<<endl;


    
return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, m, p[20], ans = 0;
    vector<vector<int> > s;
    cin >> n >> m;
    s.resize(m);
    REP(i,m){
        int k;
        cin >> k;
        REP(j,k){
            int t;
            cin >> t;
            s[i].push_back(t-1);
        }
    }
    REP(i,m){
        cin >> p[i];
    }
    REP(i,(1<<n)){
        int cnt[20]{}, tmp = 0;
        REP(j,m){
            for(auto k : s[j]){
                cnt[j] += (i>>k)&1;
            }
            if(cnt[j]%2==p[j])tmp++;
        }
        if(tmp==m)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,k,p,cnt,n,m;
    int a[10010];
    int c[110][110];
    cin>>n>>m;
    cin>>k;
    for(i=1;i<=k;i++)
        scanf("%d",&a[i]);
    p=1;cnt=0;
    for(i=1;i<=n;i++)
    {
        if (i & 1)
        {
            for(j=1;j<=m;j++)
            {
                c[i][j]=p;
                cnt++;
                if (cnt==a[p]) {p++;cnt=0;}
            }
        }
        else
        {
            for(j=m;j>=1;j--)
            {
                c[i][j]=p;
                cnt++;
                if (cnt==a[p]) {p++;cnt=0;}
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
            if (j==m) printf("%d\n",c[i][j]);
            else printf("%d ",c[i][j]);
    }
    return 0;
}

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


int main(){

    long long A, B;
    long N;

    cin >> A >> B >> N;
    long long x = N;
    if(N >= B-1) x = B -1;
    long long ans = A * (x%B)/B;
    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   //左半分を白　右　黒　で塗って置く。必要数だけ点を打っていく。
           int a,b;
           cin>>a>>b;
           a--;b--;
           int h=100,w=100;
           vst ans(h,"");
           rep(i,0,h){
            rep(j,0,w){
             if(j<50){
               ans[i]+='.';
             }
             else{
               ans[i]+='#';
             }
            }
           }
           /////////////
           int num=0;
           int bh=0,bw=0;
           while(b>num){
             ans[bh][bw]='#';
             bh+=2;
             if(bh>=h){
              bh=0;
               bw+=2;
             }
             num++;
           }
           int ah=0,aw=w-1;
           num=0;
           while(a>num){
             ans[ah][aw]='.';
             ah+=2;
             if(ah>=h){
              ah=0;
               aw-=2;
             }
             num++;
           }
           cout<<h<<" "<<w<<endl;
           rep(i,0,h)cout<<ans[i]<<endl;
}

Measured memory_bytes: 3652
import os
import heapq
import math


def main():
    N, M = (int(x) for x in input().split())
    cost = [-a for a in map(int, input().split())]
    # print(cost)
    heapq.heapify(cost)
    # print(cost)
    for _ in range(0, M):
        x = heapq.heappop(cost)
        # print(x)
        heapq.heappush(cost, x/2)
        # print(cost)
    res = 0
    for i in range(0, N):
        # res += math.floor(cost[i]*-1)
        res += int(cost[i]*-1)

    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14532
#include <stdio.h>

int main(void) {
	long int s;
	scanf("%ld", &s);

	int i = 0;
	if (s == 1 || s == 2 || s == 4) {
		printf("4\n");
	}
	else {
		while (1) {
			if (s == 4) {
				break;
			}
			else {
				s = (s % 2 == 0) ? s / 2 : 3 * s + 1;
				i++;
			}
		}

		printf("%d\n", i + 4);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  ios_base::sync_with_stdio(false); 
    cin.tie(NULL);    
  
	 long long n,i,j,k,sum=0,ans=0,count=0,c1=0,c2=0,x=-1,p,mn;
	 cin>>n>>k>>p;
	 count=k+p;
	 if(n%count==0)
	 {
	     cout<<(n/count)*k;
	 }
	 else
	 {
	     cout<<(n/count)*k+min(n%count,k);
	 }
}

Measured memory_bytes: 256
from itertools import *
def count_inversion(sequence):
    return sum(sum(m<n for m in sequence[i+1:]) for i,n in enumerate(sequence))

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

up = []
down = []
for i in range(n):
    if i % 2 == 0:
        up.append((a[i], i))
        down.append((b[i], i))
    else:
        up.append((b[i], i))
        down.append((a[i], i))

up.sort()
l = set([i for i in range(n)])

ans = 10000
for u in combinations(up, (n+1)//2):
    index = []
    value = []
    for val, ind in u:
        index.append(ind)
        value.append(val)

    d_index = l - set(index)
    d = []
    for i in d_index:
        d.append(down[i])
    d.sort()
    value.append(100)
    flag = 1
    for i in range(len(d)):
        if not value[i] <= d[i][0] <= value[i+1]:
            flag = 0
            break
    if flag == 0:
        continue

    for i in range(len(d)):
        index.insert(2*i+1, d[i][1])

    ans = min(ans, count_inversion(index))



if ans == 10000:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 52572
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val A = readInputLine().split(" ").map { it.toInt() }
    val B = readInputLine().split(" ").map { it.toInt() }
    val C = readInputLine().split(" ").map { it.toInt() }
    
    var ans = 0
    var bef = Int.MIN_VALUE
    
    for (a in A) {
        ans += B[a - 1]
        if (a == bef + 1) {
            ans += C[bef - 1]
        }
        bef = a
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36076
N = int(input())
a = list(map(int, input().split()))
li = [0] * 8
ans = 0
cnt = 0
for x in a:
    if x // 400 < 8:
        li[x//400] += 1
    else:
        cnt += 1
for i in range(8):
    if li[i] > 0:
        ans += 1

r = [max(1,ans), ans+cnt]
print(*r)

Measured memory_bytes: 38384
// https://yamakasa.net/atcoder-agc-039-a/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
int main() {
    string S;
    ll K;
    cin >> S >> K;
    ll n = S.length();
    if(n == 1) {
        cout << K / 2 << "\n";
        return 0;
    }
    ll cnt = 1;
    REP(i, n - 1) {
        if(S[i] == S[i + 1]) {
            cnt++;
        }
    }
    if(cnt == n) {
        cout << K * n / 2 << endl;
        return 0;
    }
    ll l = 0;
    ll r = 0;
    for(int i = 0; i < n; i++) {
        if(S[0] == S[i]) {
            l++;
        } else {
            break;
        }
    }
    if(l == n) {
        cout << n * K / 2 << "\n";
        return 0;
    }
    for(int i = n - 1; i >= 0; i--) {
        if(S[n - 1] == S[i]) {
            r++;
        } else {
            break;
        }
    }
    if(l + r == n) {
        // S[0] != S[n - 1]
        // aaaaa nnnnnnnみたいなの
        ll ans = l / 2 * K + r / 2 * K;
        cout << ans << "\n";
        return 0;
    }
    ll ans = 0;
    ll c = 1;
    for(int i = l; i < n - r; i++) {
        if(S[i] == S[i + 1]) {
            c++;
        } else {
            ans += c / 2 * K;
            c = 1;
        }
    }
    ans += c / 2 * (K - 1);

    if(S[0] == S[n - 1]) {
        ans += l / 2 + (l + r) / 2 * (K - 1) + r / 2;
    } else {
        ans += l / 2 * K + r / 2 * K;
    }
    // cout << l << " " << r << "\n";
    cout << ans << "\n";
    return 0;
}

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

long long H, W, D, Q;
long long L, R;
long long d[90001];
long long px[90001];
long long py[90001];

int main(){
	cin >> H >> W >> D;
	for(long long i = 0; i < H; i++){
		for(long long j = 0; j < W; j++){
			long long tmp;
			cin >> tmp;
			//py[tmp] = i;
			//px[tmp] = j;
			py[tmp] = j;
			px[tmp] = i;
		}
	}

	//for(long long i = D + 1; i <= H*D; i++){
	//	d[i] = d[i-D] + abs(py[i] - py[i-D]) + abs(px[i] - px[i-D]);
	//}
	for(int i=D+1;i<=H*W;i++)
		d[i]=d[i-D]+abs(px[i]-px[i-D])+ abs(py[i]-py[i-D]);

	cin >> Q;
	for(long long i = 0; i < Q; i++){
		cin >> L >> R;
		cout << d[R] - d[L] << endl;
	}

	//scanf ("%d",&Q);
	//while(Q--){
	//	scanf ("%d%d",&L,&R);
	//	printf ("%d\n",d[R]-d[L]);
	//}
}


Measured memory_bytes: 3200
ary = gets.split(' ').map(&:to_i)
ps = ary[0] + ary[1]
ms = ary[0] - ary[1]
ss = ary[0] * ary[1]
re = 0
if ps > ms
  re = ps if ps > ss
  re = ss if ss > ps
else
  re = ms if ms > ss
  re = ss if ss > ms 
end
p re

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int> A(N+1);
  vector<int> ten(N+1);
  vector<int> ch(N+2);
  ten.at(0)=1;
  for(int i=0;i<N;i++){
    A.at(i+1) = A.at(i) + (S[N-i-1]-'0')*ten.at(i);
    A.at(i+1) %= 2019;
    ten.at(i+1)=ten.at(i)*10%2019;
  }
  int s=0;
  for(int i=0;i<N-3;i++){
    if(ch.at(i))
      continue;
    vector<int> a;
    for(int j=i+4;j<=N;j++){
      if((A.at(j)-A.at(i)) % 2019 == 0) {
        s++;
        ch.at(j)=1;
        j+=3;
        a.push_back(j);
      }
    }
    int b=a.size();
    s += b*(b-1)/2;
  }
  cout << s << endl;
}




Measured memory_bytes: 5956
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    long long ans = 1;
    for(int i=0; i<N; i++) ans *= 3;
    long long tmp = 1;
    for(int i=0; i<N; i++){
        if(A[i] % 2 == 0) tmp *= 2;
    }
    cout << ans - tmp << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io;


fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> i64 {
    return s.trim().parse()
        .expect("Please type a number!");
}

fn main() {

    let line = read_line();
    let abc: Vec<&str> = line.split(' ').collect();

    let a: i64 = to_i(abc[0]);
    let b: i64 = to_i(abc[1]);
    let c: i64 = to_i(abc[2]);


    let result = a>0 && a==b && b==c && c==a;
    if result {
        print!("Yes");
    } else {
        print!("No");
    }

    

}   

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
class modint{
public:
  long long x;
  constexpr modint(long long x=0):x((x%MOD+MOD)%MOD){}
  constexpr modint operator-() const{return modint(-x);}
  constexpr modint& operator+=(const modint& a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator-=(const modint& a){
    if((x+=MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  constexpr modint& operator*=(const modint& a){
    (x*=a.x)%=MOD;
    return *this;
  }
  constexpr modint operator+(const modint& a) const{return modint(*this)+=a;}
  constexpr modint operator-(const modint& a) const{return modint(*this)-=a;}
  constexpr modint operator*(const modint& a) const{return modint(*this)*=a;}
  constexpr bool operator==(const modint& a) const{return this->x==a.x;}
  constexpr bool operator!=(const modint& a) const{return this->x!=a.x;}
  constexpr modint pow(long long expo) const{
    if(expo==0)  return 1;
    modint a=pow(expo>>1);
    a*=a;
    if(expo&1)  a*=(*this);
    return a;
  }
  //for prime MOD
  constexpr modint inv() const{return pow(MOD-2);}
  constexpr modint& operator/=(const modint& a){return (*this)*=a.inv();}
  constexpr modint operator/(const modint& a) const{return modint(*this)/=a;}
};
istream& operator>>(istream& is,const modint& a){return is >> a.x;}
ostream& operator<<(ostream& os,const modint& a){return os << a.x;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,K;
  cin >> N >> K;

  vector<modint> calc(K+1,0);
  for(int i=K;i>=1;i--){
    modint tmp=K/i;
    tmp=tmp.pow(N);
    for(int j=2*i;j<=K;j+=i)  tmp-=calc.at(j);
    calc.at(i)=tmp;
  }
  modint ans=0;
  for(int i=1;i<=K;i++) ans+=calc.at(i)*i;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3992
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1000100

/* RangeMinimumQuery(0-index) */

struct RMQ{
  typedef int Type;
  int segn2;
  Type inf;
  vector<Type> data;
  
  RMQ(int n){
    inf = INF; //init value
    for(segn2=1;segn2<n;segn2*=2);
    data.assign(segn2*2,inf);
  }
  
  //get minimum value [a,b]
  Type query(int a,int b,int l=0,int r=-1,int k=0){
    if(r==-1) r+=segn2;
    if(a<=l && r<=b) return data[k];
    if(r<a || b<l) return inf;
    return min(query(a,b,l,(l+r)/2,k*2+1),query(a,b,(l+r)/2+1,r,k*2+2));
  }
  
  //set kth number x
  void set(int k,Type x){
    k+=segn2-1;
    data[k]=x;
    while(k>0){
      k=(k-1)/2;
      data[k]=min(data[k*2+1],data[k*2+2]);
    }
    return;
  }
};

int n,m;
int c[SIZE];

int ans[SIZE];
vector<int> vec[SIZE];
int rest[SIZE];

RMQ rmq(SIZE);

void calc(int mode){
  
  c[n] = -1;
  
  for(int i=0;i<m;i++){
    rest[i] = n - vec[i].size();
    rmq.set(i, rest[i]);
  }

  for(int i=0;i<m;i++){
    int minus_sum = 0;

    for(int j=0;j<(int)vec[i].size();j++){
      int a = (vec[i][j]-mode)/2*2+mode; //c[a] == i
      int b = a; //c[b] != i

      if((mode == 0 && n%2 == 1 && vec[i][j]==n-1) ||
         (mode == 1 && (vec[i][j]==0 || (n%2==0 && vec[i][j]==n-1)))){
        minus_sum++;
        continue;
      }

      if(c[a] == i) b++;
      else a++;
      
      if(c[a] == c[b]){
        if(a == vec[i][j]) minus_sum+=2;
        continue;
      }

      minus_sum++;
      rest[c[b]]++;
      rmq.set(c[b], rest[c[b]]);
      /*
      debug(b);
      debug(c[b]);
      debug(mode);
      debug(vec[i][j]);
      */
    }
    
    int this_ans = min(rmq.query(-INF,i-1),rmq.query(i+1,m)) - minus_sum;

    ans[i] = min(ans[i], this_ans);

    //cerr << mode << " " << i << " : " << this_ans << " (" << minus_sum << ")" << endl;

    for(int j=0;j<(int)vec[i].size();j++){
      int a = (vec[i][j]-mode)/2*2+mode; //c[a] == i
      int b = a; //c[b] != i

      if((mode == 0 && n%2 == 1 && vec[i][j]==n-1) ||
         (mode == 1 && (vec[i][j]==0 || (n%2==0 && vec[i][j]==n-1)))){
        continue;
      }

      if(c[a] == i) b++;
      else a++;
      
      if(c[a] == c[b]){
        continue;
      }

      rest[c[b]]--;
      rmq.set(c[b], rest[c[b]]);
    }
     
  }

}
  
  

int main(){

  scanf("%d%d",&n,&m);
  
  if(m == 1){
    puts("0");
    return 0;
  }

  for(int i=0;i<m;i++){
    ans[i] = INF;
  }
  
  for(int i=0;i<n;i++){
    scanf("%d",c+i);
    c[i]--;
  }
 
  for(int i=0;i<n;i++){
    vec[c[i]].push_back(i);
  }
  
  // |1 2|3 4|5 6|7 ...

  calc(0);
  calc(1);

  for(int i=0;i<m;i++){
    printf("%d\n",ans[i]);
  }
  
  return 0;
}

Measured memory_bytes: 77496
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n, m; cin >> n >> m;
    set<int> former;
    set<int> latter;

    rep(i,m){
        int a, b; cin >> a >> b;
        if(a == 1){
            former.insert(b);
        }
        if(b == n){
            latter.insert(a);
        }
    }

    for(auto itr = former.begin(); itr != former.end(); ++itr) {
        if (latter.find(*itr) != latter.end()) {
        cout << "POSSIBLE" << endl;
        return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 9600
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main(void){
   char s[300];
   int i;
   scanf("%[^\n]", s);
   for ( i = 0; i < strlen(s); i++ ) {
       s[i] = toupper(s[i]);
   }
   printf("%s\n", s);
   return 0;
}

Measured memory_bytes: 1664