akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define int long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second

    using namespace std;
int power(int base, int exp)
{
    if (exp == 0)
       return 1;
    else if (exp == 1)
       return base;
    else
    {
       int calc;
       if (exp % 2 == 0)
       {
         calc = power(base, exp/2);
         calc =(calc* calc)%mod;
       }
       else
       {
         calc = (base*power(base, exp-1))%mod;
       }
       return calc%mod;
    }
}
    int32_t main()
    {
        std::ios::sync_with_stdio(false);
           int k;
           cin>>k;
           int l,r;
           cin>>l>>r;
           int f=0;
           for(int i=l;i<=r;i++)
           {
               if(i%k==0)
               {
                   f=1;
                   break;
               }
           }
           if(f)
            cout<<"OK"<<endl;
           else
            cout<<"NG"<<endl;
        return 0;
    }


Measured memory_bytes: 3636
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		int K = sc.nextInt();
		
		long[] A = new long[X];
		long[] B = new long[Y];
		long[] C = new long[Z];
		
		for(int i=0;i<X;i++) {
			A[i] = sc.nextLong();
		}
		for(int i=0;i<Y;i++) {
			B[i] = sc.nextLong();
		}
		for(int i=0;i<Z;i++) {
			C[i] = sc.nextLong();
		}
		
		long[] AB = new long[X*Y];
		for(int i=0;i<A.length;i++) {
			for(int j=0;j<B.length;j++) {
				AB[i*B.length+j] = A[i] + B[j];
			}
		}
		
		Arrays.sort(AB);
		long[] AB2 = new long[Math.min(K, AB.length)];
		for(int i=0;i<AB2.length;i++) {
			AB2[i] = AB[AB.length-i-1];
		}
		AB = null;
		
		long[] ABC = new long[K*Z];
		for(int i=0;i<AB2.length;i++) {
			for(int j=0;j<C.length;j++) {
				ABC[i*C.length+j] = AB2[i] + C[j];
			}
		}
		Arrays.sort(ABC);
		
		for(int i=0;i<Math.min(K,ABC.length);i++) {
			out.println(ABC[ABC.length-i-1]);
		}
		
		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 62552
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int N =sc.nextInt();//N人
      int K =sc.nextInt();//Kポイント
      int Q =sc.nextInt();//Q回戦
      
      int n[] =new int[N];
      int a[] =new int[Q];//入力されるであろう勝った人の番号を格納する
      
      for(int j=0; j<Q; j++){
      a[j] =sc.nextInt();
      }
      
      int kq = K-Q;//一回も答えれなかったときのポイント
      Arrays.fill(n,kq);//n[N]の中身の初期値を一回も答えれなかった時のポイントに設定しておく
      
      for(int j=0; j<Q; j++){
		n[a[j]-1]++;//a[3]...aの0番目に入っているのは3,しかし配列だとn[3]=2であるため-1をしている
      }
      for(int j=0; j<N; j++){
        if(n[j]<=0){//n[j]==加算された数が入っている,0,0,1,-1,-1,-1
        System.out.println("No");
        }
        else{
        System.out.println("Yes");
        }
        }
    }
}
     

Measured memory_bytes: 60888
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define get(a) ll a; cin >> a;
#define show(a) cout << a << endl;
#define full(p) p.begin(), p.end()
#define sz(a) (ll)(a.size())
#define pb push_back
 
 
bool not_month(int a)
{
	if(a > 12 or a == 0)
		return true;
	return false;
}
 
 
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout<<fixed;
	////////////////////////////////
	get(s);
 
	int a = s/100;
	int b = s%100;
 
	if(not_month(a) and not_month(b))
		cout << "NA" << endl;
	else if(not_month(a) and !not_month(b))
		cout << "YYMM" << endl;
	else if(!not_month(a) and not_month(b))
		cout << "MMYY" << endl;
	else if(!not_month(a) and !not_month(b))
		cout << "AMBIGUOUS" << endl;
	return 0;
}

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

using namespace std;


int main(void){
    int n,y;
    cin>>n>>y;
    int a,b;
    
    for(int i=0;i<n+1;i++){
        a=i;
        for(int j=0;j<n+1;j++){
            b=j;
            if(9000*a+4000*b==y-1000*n){
                if(n-a-b<0)break;
                cout<<a<<" "<<b<<" "<<n-a-b<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mod=1000000007;

int main()
{
    ios::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin>>n;
  string s;
  while(n){
    if(n%26==0){s.push_back('z');
    n=n/26;
    n--;
    }
    else{s.push_back((char)('a'+n%26-1));
    n=n/26;
    }
  }
  reverse(s.begin(),s.end());
  cout<<s;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;

map<long long int, long long int> m;

void solve(long long int h){
  if (h == 1){
    m[h] = 1;
    return;
  }



  if (m.find(h / 2) == m.end())
    solve(h / 2);

  m[h] = 2 * m[h / 2] + 1;

  return;
}


int main(void){

  long long int h;

  cin >> h;

  solve(h);

  cout << m[h] << endl;

  

  return 0;
}


Measured memory_bytes: 256
program answer
  implicit none
  integer(8) :: i, N, M, sum, last, count
  integer(8), allocatable :: A(:), B(:)
  read(*,*) N, M
  allocate(A(N),B(N))
  do i = 1, N
     read(*,*) A(i), B(i)
  end do
  A(:)=A(:)*100001+B(:)
  call msort(A)
  do i = 1, N
     B(i)=mod(A(i),100001)
     A(i)=(A(i)-B(i))/100001
  end do
 
  sum=0
  count=0
  i=1
  do
     if(count>=M) then
        exit
     end if
     sum=sum+A(i)*B(i)
     count=count+B(i)
     last=i
     i=i+1
  end do

  if(count>M) then
     sum=sum-(count-M)*A(last)
  end if

  write(*,*) sum
  deallocate(A,B)
  stop
contains
  !merge sort
  recursive subroutine msort(array)
    implicit none
    integer(8) :: i, j, k, N, mid, array(:)
    integer(8), allocatable :: tmp(:)
    N=size(array)
    allocate(tmp(N))
    if(n==1) then
       return
    end if
    !1~mid,mid+1~nと前半,後半に分けてsort
    mid=n/2
    call msort(array(1:mid))
    call msort(array(mid+1:n))
    tmp=array
    !tmpの後半部分を左右反転
    do k = n, mid+1, -1
       tmp(k)=array(n+mid-k+1)
    end do
    !iは前半のリストのうちまだ見ていないものの最小値
    !jは後半のリストのうちまだ見ていないものの最小値
    !kは見た回数の合計
    i=1
    j=n
    do k = 1, n !1番左と一番右のうち小さい方をarrayに入れていく
       if(tmp(i)<=tmp(j)) then 
          array(k)=tmp(i)
          i=i+1
       else
          array(k)=tmp(j)
          j=j-1
       end if
    end do
    return
  end subroutine msort
 end program answer

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

int main(){
  int n;
  cin >> n;
  map<int, int> higr;
  map<int, int> higl;
  for(int i=0; i<n; ++i){
    int x;
    cin >> x;
    ++higr[x-i];
    ++higl[-x-i];
  }
  long long ans=0;
  for(const auto& [key,value] : higr){
    ans += (ll)value * (ll)higl[key];
  }
  cout << ans << endl;
}

Measured memory_bytes: 29296
#include <iostream>
using namespace std;
#define MAX 5000000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j]) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(int A[], int n, int left, int right)
{
    if (left+1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int main()
{
    int A[MAX], n, i;
    cnt = 0;

    cin >> n;
    for (i = 0; i < n; i++) cin >> A[i];

    mergeSort(A, n, 0, n);

    for (i = 0; i < n; i++) {
        if (i) cout << ' ';
        cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 7036
n,m,*a=map(int,open(0).read().split())
for i in range(1001):
    if len(str(i))==n:
        if sum(str(i)[s-1]==str(c)for s,c in zip(a[::2],a[1::2]))==m:
            print(i)
            exit()
print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    long long n; std::cin >> n;
    long long w = n;
    int ans = 0;
    for (long long i = 2; i*i <= n; i++) {
        if (w % i != 0) continue;
        int cnt = 0;
        while (w > 0 && w % i == 0) {
            cnt++;
            w /= i;
        }
        int t = 1;
        while (cnt - t >= 0) {
            ans++;
            cnt -= t;
            t++;
        }
    }
    if (w > 1) ans++;
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


int main(){
    int N,A,B;
    cin>>N>>A>>B;
    if((B-A)%2==0)cout<<"Alice"<<endl;//差が偶数なら先手の勝ち
    else cout<<"Borys"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
int main(){
  std::string s;
  int n;
  std::cin>>n>>s;
  for(int i=0;i!=s.size();++i){
    std::cout<<(s[i]+n>90?(char)(s[i]+n-26):(char)(s[i]+n));
  }
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

void bfs(const vector<vector<int>> &v,vector<int> &ans,vector<int> &x, int t,int now,int past){

    ans[now] = t + x[now];
    int new_t = t + x[now];
    rep(i,v[now].size()){
        if(v[now][i]==past)continue;
        int new_t = t + x[now];
        bfs(v,ans,x,new_t,v[now][i],now);  
    }
    return;
}


int main(){

    ll n,q;
    cin >> n >> q;
    vector<vector<int>> v(n);

    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    vector<int> x(n,0);
    rep(i,q){
        int p,k;
        cin >> p >> k;
        p--;
        x[p]+= k;
    }
    vector<int> ans(n,0);

    bfs(v,ans,x,0,0,-1);

    rep(i,n)cout << ans[i] << ' ';
    cout << endl;

    return 0;
}  

Measured memory_bytes: 33664
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long K = sc.nextLong();
        if (K <= A) {
            A = A - K;
            K = 0;
        } else {
            K = K - A;
            A = 0;
        }
        if (K <= B) {
            B = B - K;
            K = 0;
        } else {
            K = K - B;
            B = 0;
        }
        System.out.println(A + " " + B);
    }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ll n,w;
    cin>>n>>w;
    vector<pair<ll,ll> > v;
    ll m=0;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        v.push_back({y,x});
        m=max(m,y);
    }
    m=m*n;
    vector<vector<ll> > dp(n,vector<ll>(m+1,-1));
    sort(v.begin(),v.end());
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<=m;j++)
        {
            if(i==0)
            {
                if(j==v[i].first)
                    dp[i][j]=v[i].second;
                continue;
            }
            if(j<v[i].first)
            {
                dp[i][j]=dp[i-1][j];
            }
            else
            {
                if(dp[i-1][j]==-1)
                {
                    if(dp[i-1][j-v[i].first]==-1 )
                    {
                        if(j==v[i].first)
                            dp[i][j]=v[i].second;
                    }
                    else
                    {
                        if(j==v[i].first)
                            dp[i][j]=v[i].second;
                        else
                            dp[i][j]=dp[i-1][j-v[i].first]+v[i].second;
                    }
                }
                else
                {
                    if(dp[i-1][j-v[i].first]!=-1)
                    {
                        dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i].first]+v[i].second);
                    }
                    else
                    {
                        if(v[i].first==j)
                        {
                            dp[i][j]=min(v[i].second,dp[i-1][j]);
                        }
                        else
                            dp[i][j]=dp[i-1][j];
                    }
                }
            }
        }
    }
    /*for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<=m;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/
    ll ans=0;
    for(ll i=m;i>=0;i--)
    {
        if(dp[n-1][i]<=w && dp[n-1][i]!=-1)
        {
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int r, D, x2000;
  cin >> r >> D >> x2000;

  int x = x2000;
  for (int i = 0; i < 10; i++) {
    x = r * x - D;
    cout << x << endl;
  }
}

Measured memory_bytes: 256
N,M=map(int,input().split())
PY=[]
for i in range(M):
	PY.append(list(map(int,input().split()))+[i,0])

PY.sort(key=lambda x:x[1])
PY.sort(key=lambda x:x[0])
#print(PY)

n=1
for i in range(M):
  if i>0:
    n = 1 if PY[i][0]!=PY[i-1][0] else n
  PY[i][3]="0"*(6-len(str(n)))+str(n)
  n+=1
  PY[i][3]="0"*(6-len(str(PY[i][0])))+str(PY[i][0])+PY[i][3]
#print(PY)
      
PY.sort(key=lambda x:x[2])
#print(PY)

for i in range(M):
  print(PY[i][3])



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

int main() {
  int N;
  cin >> N;
  
  int judge = 0;
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    
    if (S == "Y") {
      judge ++;
    }
    // 黄色のひなあられがある場合、judgeは1以上
  }
  
  if (judge == 0) {
    cout << "Three" << endl;
  } else {
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 256
/*+lmake
 * STD = c++14
 * DEFINE += MDEBUG
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

void solve(long long N, vector<long long> L){
	sort(L.begin(),L.end());
	int ans=0;
	for(int i=0; i<N; ++i) {
		ans+=L[i*2];
	}
	cout<<ans<<endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> L(2*N-1+1);
	for(int i = 0 ; i <= 2*N-1 ; i++){
		scanf("%lld",&L[i]);
	}
	solve(N, L);
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;


Node root;

Node tSearch(Node u, int v);

void insert(int u);

void inorder(Node u);

void preorder(Node u);

int main(){
  int b,n,i;
  char a[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", a);
    if ( a[0] == 'i' ){
      scanf("%d", &b);
      insert(b);
    } else if ( a[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( a[0] == 'f' ){
      scanf("%d", &b);
      Node t = tSearch(root,b);
      if ( t != N ) printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}



Node tSearch(Node u, int v){
    if(u == N || v == u->key)return u;

    if(v < u->key)return tSearch(u->left,v);

    else return tSearch(u->right,v);
    
}

void insert(int u){
  Node y = N;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = u;
  z->left = N;
  z->right = N;

  while(x != N){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;

  if(y == N)root = z;

  else if(z->key < y->key)y->left = z;

  else y->right = z;
}

void inorder(Node u){
  if(u != N){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }

}
void preorder(Node u){
  if(u==NULL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}




Measured memory_bytes: 20448
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()
using namespace std;


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

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

    // int min = vec[0];
    // int max = vec[n-1];
    int min = *min_element(ALL(vec));
    int max = *max_element(ALL(vec));

    int minCost = INT_MAX;
    for(int pos = min; pos <= max; ++pos){
        int cost = 0;
        for(int i = 0; i < n; ++i){
            cost += pow((vec[i] - pos), 2);
        }
        if(cost < minCost){
            minCost = cost;
        }
    }

    cout << minCost << endl;
}

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

using namespace std;

bool isPalindrome(const string& A) {
  string B = A;
  reverse(B.begin(), B.end());
  return A == B;
}

int main() {
  string S;
  cin >> S;
  int N = S.length();
  string A = S.substr(0, (N - 1) / 2);
  string B = S.substr((N - 1) / 2 + 1);

  if (isPalindrome(S) && isPalindrome(A) && isPalindrome(B)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K; cin >> N >> K;
  long long a[5011];
  for(int i = 0; i < N; ++i) {
    cin >> a[i];
  }
 
  sort(a, a + N);
 
  long long sum = 0;
  int ans = N;
  for(int i = N-1; i >= 0; --i) {
    if(sum + a[i] < K) sum += a[i];
    else ans = min(ans, i);
  }
  cout << ans << endl;
 
  return 0;
}

    

Measured memory_bytes: 256
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <set>
#include <map>
#include <bitset>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = -1;
		cin >> n;
		if (n < 0) return 0;
		LL ans = 0, cnt = 1, index = 0;
		vector<int> a(n);
		for (LL i = 0; i < n; ++i) {
			cin >> a[i];
		}
		sort(a.rbegin(), a.rend());
		for (LL t = 1; t < n; ++t) {
			ans += a[index];
			if (++cnt >= 2) {
				cnt = 0;
				++index;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3984
#include <stdio.h>

int gcd(int m, int n){
    
    int r;
    while(1){
        r = m % n;
        if(r != 0){
            m = n;
            n = r;
        } else{
            break;
        }
    }
    return n;
}

int main(){
    
    int m, n;
    scanf("%d", &m);
    scanf("%d", &n);

    int max = m > n ? m : n;
    int min = m > n ? n : m;

    printf("%d\n", gcd(max, min));

    return 0;

}


Measured memory_bytes: 1992
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ov = []
un = 0
cnt = 0
for i in range(n):
  c = a[i]-b[i]
  if c >= 0:
    ov.append(c)
  else:
    un += c
    cnt += 1
if un == 0:
  print(0)
else:
  un *= -1
  ov.sort(reverse=True)
  ov2 = 0
  for i in range(len(ov)):
    ov2 += ov[i]
    if ov2 >= un:
      print(cnt+i+1)
      break
  else:
    print(-1)

Measured memory_bytes: 18356
#include <bits/stdc++.h>
using namespace std;
int a[300001],A[300001];
int main(void)
{

	int n,q;
	int x,y;
	
	int cnt=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		A[i]=a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(a[i]==A[i]){
			cnt++;
		}
	}
	if(cnt==n){
		cout<<0<<endl;
		return 0;
	}
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>x>>y;
		x--;y--;
		if(a[x]==A[x]){
			cnt--;
		}
		if(a[y]==A[y]){
			cnt--;
		}
		swap(A[x],A[y]);
		if(a[x]==A[x]){
			cnt++;
		}
		if(a[y]==A[y]){
			cnt++;
		}
		if(cnt==n){
			cout<<i+1<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

		


Measured memory_bytes: 5520
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;

ll pow(ll x, ll n, int mod=MOD){
    ll res = 1;
    while(n){
        if(n%2){
            res = (res * x)%mod;
        }
        n >>= 1;
        x = (x*x)%mod;
    }
    return res%mod;
}

struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // get lcp of S[a:] and T[b:]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};

signed main(){
    int N; cin>>N;
    string s; cin >>s;

    RollingHash rh(s);

    int res = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            int lcp = rh.getLCP(i, j);
            lcp = min(lcp, j-i);
            res = max(res, lcp);
        }
    }   
        
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) sort(v.begin(), v.end())
typedef long long ll;
using Graph = vector<vector<int>>;
const int mod = 1000000007;

int main()
{
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 3)
  {
    if (s.at(i) == '1')
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    if (s == t.substr(0, s.size())) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <tuple>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG

int main(void){
    int x;
    cin >> x;
    if(x == 0){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }

}

Measured memory_bytes: 3548
sx,sy,tx,ty = map(int,input().split())

short_outward = []
short_return = []
long_outward = ["L"]
long_return = ["R"]

for i in range((ty-sy)):
    short_outward.append("U")

for i in range((tx-sx)):
    short_outward.append("R")


for i in range((ty-sy)):
    short_return.append("D")

for i in range((tx-sx)):
    short_return.append("L")


for i in range((ty-sy)+1):
    long_outward.append("U")

for i in range((tx-sx)+1):
    long_outward.append("R")

long_outward.append("D")



for i in range((ty-sy)+1):
    long_return.append("D")

for i in range((tx-sx)+1):
    long_return.append("L")

long_return.append("U")



list = short_outward+short_return+long_outward+long_return

for i in range(len(list)):
    print(list[i],end="")


Measured memory_bytes: 9316
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
const int INF = 1000100100;

int main(){
    ll a,b,c,d,max=-1000000000000000000;
    cin>>a>>b>>c>>d;
    if(a*c>max){
        max=a*c;
    }
    if(a*d>max){
        max=a*d;
    }
    if(b*c>max){
        max=b*c;
    }
    if(b*d>max){
        max=b*d;
    }
    cout<<max;
}

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

int main(){
  int N,a,b,c,d;
  
  cin >> N;
  
  a=N/1000;
  b=N/100-10*a;
  c=N/10-100*a-10*b;
  d=N-1000*a-100*b-10*c;
  
  if(a==b && b==c){
     cout <<"Yes"<<endl;
  }
  else if(b==c && c==d){
    cout <<"Yes"<<endl;
  }
  else {
    cout <<"No"<<endl;
  }
}

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

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;

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

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


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

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

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

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

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

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

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

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

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

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

int main() {
  int H, W, N, Y, X;
  string S, T;
  cin >> H >> W >> N;
  cin >> Y >> X;
  --Y, --X;
  cin >> S >> T;
  const int d[] = {-1, 1, -1, 1};
  string V = "LRUD";
  for(int i = 0; i < 4; i++) {
    int pon = i <= 1 ? X : Y;
    int n = i <= 1 ? W : H;
    for(int j = 0; j < N; j++) {
      if(S[j] == V[i]) pon += d[i];
      if(pon < 0 || pon >= n) {
        cout << "NO" << endl;
        return 0;
      }
      if(T[j] == V[i ^ 1]) {
        pon -= d[i];
        if(pon < 0 || pon >= n) pon += d[i];
      }
    }
  }
  cout << "YES" << endl;
}




Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, Q; string S; 
	cin >> N >> S >> Q;
	set<int> T[26]; 
	for(int i = 0; i < 26; i++){
		T[i].insert(-1145141919); 
		T[i].insert(1145141919); 
	}
	for(int i = 1; i <= N; i++){
		int a = S.at(i-1) - 'a';  
		T[a].insert(i); 
	}
	while(Q--){
		int a; cin >> a; 
		if(a == 1){
			int x; char c; cin >> x >> c; 
			T[S.at(x-1) - 'a'].erase(x);  
			T[c - 'a'].insert(x); 
			S.at(x-1) = c; 
		}
		if(a == 2){
			int x, y; cin >> x >> y; 
			int cnt = 0; 
			for(int i = 0; i < 26; i++){
				if(*T[i].lower_bound(x) <= y) cnt ++; 
			}
			cout << cnt << endl; 
		}
	} 
}

Measured memory_bytes: 24196
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var line = System.Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

        var same = line[0] == line[1] && line[2] == line[1];
        var other = line[0] != line[1] && line[2] != line[1] && line[0]  != line[2];

        if(same || other)
        {
            System.Console.WriteLine("No");
        }
        else
        {
            System.Console.WriteLine("Yes");
        }

    }


}



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

using namespace std;
#define rep(i,n) for(int i = 0;i < (int)n;i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int,int>;
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};
//const int INF = (1 << 29);


int main(){

  int a,p;
  cin >> a >> p;
  cout << (a*3+p)/2;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
//const ll MOD = 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

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


    int n;
    int a_sum, b_sum;

    while (1) {
        cin >> n;
        if (n == 0) break;
        a_sum = 0, b_sum = 0;

        rep(i, n) {
            int a, b;
            cin >> a >> b;
            if (a > b) a_sum += a + b;
            else if (a < b) b_sum += a + b;
            else a_sum += a, b_sum += b;
        }
        cout << a_sum << " " << b_sum << endl;
    }

    return 0;
}




Measured memory_bytes: 3024
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl


int main(){
  ll n,m;cin>>n>>m;
  ll ans=1;
  FOR(i,1,100001){
    if(m%i==0&&m/i>=n){
      ans=max(ans,ll(i));
    }
    if(m%i==0&&i>=n){
      ans=max(ans,ll(m/i));
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
	int x = 1;
	int n = 1;
	while (true) {
		cin >> x;
		if (x == 0)break;
		cout << "Case " << n << ": " << x << endl;
		n++;
	}
    return 0;
}

Measured memory_bytes: 1160
def CDP(h,w,k):
  q=[]
  ans=0
  d=-1
  m=0
  while True:
    if d==ans:break
    d=ans
    for i in range(h):
      cnt=0
      for j in range(w-1):
        if a[j][i]==a[j+1][i]:cnt+=1
        else:
          if cnt>=k-1:
            q.append((j-cnt,i,cnt+1))
          cnt=0
      if cnt>=k-1:
        q.append((w-cnt-1,i,cnt+1))      
    while q:
      j,i,cnt=q.pop()
      for c in range(cnt):
        ans+=a[j+c].pop(i)
        a[j+c].append(0)
  return ans

while True:
  h=int(input())
  if h==0:break
  b=[list(i[::-1]) for i in zip(*[input().split() for _ in range(h)])]
  a=[[int(s) for s in strs] for strs in b]
  print(CDP(h,5,3))


Measured memory_bytes: 5628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

using namespace std;



int main()

{
	string A,B,C;

	cin >> A >> B>>C;
	int a = A.size();
	int b = B.size();
	int c = C.size();

	if (A[a - 1] == B[0] && B[b - 1] == C[0])
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	
	

	return 0;
	
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
S=list(input())
dic = {}

for s in S:
    dic[s] = 0

for s in S:
    dic[s] += 1

if len(dic) == 2:
    flag = True
    for v in dic.values():
        if v != 2:
            flag = False
    
    if flag == True:
        print("Yes")
    else:
        print("No")

else:
    print("No")

Measured memory_bytes: 38336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;

int main() {
    int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    vector<int> p(A); for (int i = 0; i < A; i++) cin >> p[i]; sort(p.begin(), p.end(), greater<int>());
    vector<int> q(B); for (int i = 0; i < B; i++) cin >> q[i]; sort(q.begin(), q.end(), greater<int>());
    vector<int> r(C); for (int i = 0; i < C; i++) cin >> r[i]; sort(r.begin(), r.end(), greater<int>());

    int i = X-1, j = Y-1, k = 0;
    int n = min({X, Y, C});
    while (true) {
        if (0 <= i && k < C && p[i] < r[k] && (j < 0 || p[i] <= q[j])) {
            i--; k++;
        } else if (0 <= j && k < C && q[j] < r[k]) {
            j--; k++;
        } else {
            break;
        }
    }
    ll ans = 0;
    for (int l = 0; l <= i; l++) ans += p[l];
    for (int l = 0; l <= j; l++) ans += q[l];
    for (int l = 0; l < k; l++) ans += r[l];

    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
vector<string> siki;
int n;
int part(int *idx,int deep,bool plus) {
	int ret = 0;
	if(plus==false)
	ret = 1;
	while (*idx != n) {
		if (deep+1 > siki[*idx].length())
			return ret;
		if (siki[*idx][deep] == '*') {
			*idx+=1;
			int a= part(idx, deep + 1, false);
			if (plus)
				ret += a;
			else
				ret *= a;
			continue;
		}
		if (siki[*idx][deep] == '+') {
			*idx+=1;
			int a= part(idx, deep + 1, true);
			if (plus)
				ret += a;
			else
				ret *= a;
			continue;
		}
		if (isdigit(siki[*idx][deep]))
			if(plus)
				ret += siki[*idx][deep]-'0';
			else
				ret *= siki[*idx][deep] - '0';
		*idx+=1;
	}
	return ret;
}

int main() {
	
	while (cin>>n,n) {
		siki.resize(n);
		REP(i, n)
			cin >> siki[i];
		int idx=0;
		cout << part(&idx,0,false) << endl;
	}
}

Measured memory_bytes: 3148
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
#include <fstream>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

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

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion


int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = min(a + b + 1, c) + b;
    cout << ans << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n,d,cnt=0;
  cin>>n>>d;
  bool ok[n+1];
  memset(ok,false,sizeof ok);
  for(int i=1;i<=n;i++){
    if(!ok[i]){
      cnt++;
      for(int j=i;j<=min(n,i+2*d);j++) ok[j]=true;
    }
  }
  cout<<cnt;
  return(0);
}

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

using namespace std;

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

    map<int, int> sum;
    int acc = 0;
    long long ans = 0;

    sum[0] = 1;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;

        acc += t;
        acc %= m;

        ans += sum[acc];
        sum[acc]++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3200
#!/usr/bin/env python3
n = int(input())
luca = [0] * 88
luca[0] = 2
luca[1] = 1
for i in range(2,87):
    luca[i] = luca[i-1] + luca[i-2]
    #print(luca[i],i)
print(luca[n])

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(long long 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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
 
int main(){
  int n,k,ans = 0;
  cin >> n >> k;
  while (n >=1) {
    n = n/k;
    ans++;
  }
  cout << ans;
}

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

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    vector<string> v;
    set<string> set_s;
    for(int i=1; i<=5; i++){
        for(int j=0; j+i-1<s.size();j++){
            string a;
            a = s.substr(j,i);
            if(!set_s.count(a)){
                v.push_back(a);
                set_s.insert(a);
            }
        }
    }
    sort(v.begin(), v.end());
    cout << v.at(k-1) << endl;
}

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

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

    if (N >= 1000) {
        while (true) {
          N -= 1000;
          if (N < 1000) {
               break;
          }
        }
    }

    if (N > 0) {
        cout << 1000 - N << endl;
    }
    else if (N == 0) {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3608
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

const int N = 1e6 + 5;

int n;
string s;

int low[N];

int check(int ub){
    int lb = 0, curr = 0;
    FOR(i,n){
        if(s[i] == '1'){
            curr++;
        }else if(s[i] == '0'){
            curr--;
        }else{
            // if pick 1 is safe
            if(curr + 1 + low[i+1] <= ub){
                curr++;
            }else{
                curr--;
            }
        }
        lb = min(lb, curr);
    }
    // printf("check lb %d, ub %d = %d\n",lb,ub,ub-lb);
    return ub - lb;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    cin>>s;
    n = s.size();

    low[n] = 0;
    FORD(i,n){
        char c = s[i];
        if(c == '?')c = '0';

        low[i] = low[i+1];
        if(c == '1') low[i]++;
        else low[i] = max(0, low[i]-1);
    }

    // FOR(i,n)printf("%d ",low[i]);printf("\n");

    int lo = low[0], hi = 1e6;
    int ans = OO;
    while(hi - lo >= 10){
        int mid1 = (lo+lo+hi)/3;
        int mid2 = (lo+hi+hi)/3;
        int v1 = check(mid1);
        int v2 = check(mid2);

        ans = min(ans, v1);
        ans = min(ans, v2);

        if(v1 < v2){
            hi = mid2;
        }else{
            lo = mid1;
        }
    }

    REP(i,lo,hi){
        ans = min(ans, check(i));
    }

    cout << ans << endl;

    // REP(i,lo,lo+10)printf("check ub %d = %d\n",i,check(i));

    return 0;
}


Measured memory_bytes: 8256
import numpy as np
N = int(input())
A = np.array([0] + [int(x) for x in input().split()] + [0])
total = np.abs(np.diff(A)).sum()
saved = np.abs(A[1:-1]-A[:-2])+np.abs(A[1:-1]-A[2:])-np.abs(A[:-2]-A[2:])
answer = total - saved
print(*answer, sep='\n')


Measured memory_bytes: 22896
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int L[N],R[N];
int main(){
	int n,k,c;
	scanf("%d %d %d\n",&n,&k,&c);
	string s;
	cin>>s;
	int cnt=k;
	int mx=n+1;
	for(int i=n-1;i>=0;i--){
		if(s[i]=='o'&&i<mx&&cnt>=1){
			R[cnt]=i,cnt--,mx=i-c;
		}
	}
	cnt=1;
	mx=-1
	;for(int i=0;i<=n-1;i++){
		if(s[i]=='o'&&i>mx&&cnt<=k){
			L[cnt]=i,cnt++,mx=i+c;
		}
	}
	for(int i=1;i<=k;i++){
		if(L[i]==R[i]) printf("%d\n",L[i]+1);
	}
	return 0;
}

Measured memory_bytes: 3332
# input
h, w = map(int, input().split())
A = [input() for _ in range(h)]

dp = [[0 for _ in range(w)] for _ in range(h)] 

dp[0][0] = 1

for i in range(1, h):
    if A[i][0] == '.':
        dp[i][0] = dp[i - 1][0]

for j in range(1, w):
    if A[0][j] == '.':
        dp[0][j] = dp[0][j - 1]

for i in range(1, h):
    for j in range(1, w):
        if A[i][j] == '.':
            dp[i][j] += (dp[i - 1][j] + dp[i][j - 1])

print(dp[h - 1][w - 1] % (10 ** 9 + 7))

Measured memory_bytes: 158452
#!/usr/bin/env python3


def solve(N):
    YES = 1
    NO = 0
    if N <= 9:
        return YES
    for a in range(1, 10):
        b = N // a
        if b * a != N:
            continue
        if b > 9:
            continue
        return YES
    return NO


if __name__ == '__main__':
    N = int(input())

    ans = solve(N)

    print(['No', 'Yes'][ans])


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

using namespace std;

class SecretOfChocolatePoles {
public:
    SecretOfChocolatePoles(int l, int k) : l(l), k(k), dp(l + 1) {};

    long long Count() {
        dp[1] = 1;
        if (k <= l) dp[k] = 1;
        for (int h = 2; h <= l; ++h) {
            if (0 <= h - 2) dp[h] += dp[h - 2];
            if (0 <= h - k - 1) dp[h] += dp[h - k - 1];
        }

        return accumulate(dp.begin(), dp.end(), 0LL);
    }
private:
    int l, k;
    vector<long long> dp;
};

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

   int l, k;
   cin >> l >> k;
   SecretOfChocolatePoles scp(l, k);
   cout << scp.Count() << '\n';

    return 0;
}



Measured memory_bytes: 3188