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

#define int long long
typedef vector<int> vi;
typedef pair<int, int> pii;
#define F first
#define S second
typedef vector<pii> vii;

struct UnionFind{
    int N;
    vi p, rank, setSize;

    UnionFind(int N){
        p.resize(N, 0);
        for(int i=0; i<N; i++) p[i] = i;
        rank.resize(N, 0);
        setSize.resize(N, 1);
    }

    int findSet(int i){ return (p[i] == i) ? i : (p[i] = findSet(p[i])); }

    bool isSameSet(int i, int j){ return findSet(i) == findSet(j); }

    void unionSet(int i, int j){
        if(!isSameSet(i, j)){
            int x = findSet(i), y = findSet(j);

            if(rank[x] > rank[y]){
                p[y] = x;
                setSize[x] += setSize[y];
            }else{
                p[x] = y;
                setSize[y] += setSize[x];
                if(rank[x] == rank[y]) rank[y]++;
            }
        }
    }

    int sizeOfSet(int i){ return setSize[findSet(i)]; }
};


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


    vii edges(M);
    for(int i=0; i<M; i++){
        int A, B;
        cin >> A >> B;
        edges[i] = {--A, --B};
    }

    vi res(M);

    int total_pairs = (N-1)*N / 2;
    res[M-1] = total_pairs;

    UnionFind UF(N);
    for(int i=M-2; i>=0; i--){
        pii x = edges[i+1];
        if(!UF.isSameSet(x.F, x.S)){
            total_pairs -= UF.sizeOfSet(x.F) * UF.sizeOfSet(x.S);
            res[i] = total_pairs;
            UF.unionSet(x.F, x.S);
        }else res[i] = res[i+1];
    }

    for(int i=0; i<M; i++) cout << res[i] << "\n";

    return 0;
}


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

using namespace std;

int main() {
  string str;
  while (getline(cin, str)) {
    for (int i = 0; i < 26; ++i) {
      for (char& c : str) {
        if (isalpha(c)) {
          if (c != 'z') ++c;
          else c = 'a';
        }
      }
      if (str.find("that") != string::npos || str.find("this") != string::npos || str.find("the") != string::npos) {
        cout << str << endl;
      }
    }
  }
}

Measured memory_bytes: 1184
#include<stdio.h>
#define MAX 100000


int A[MAX],n;

int partition(int p, int r){
  int x,i,j,t;
  x =A[r];
  i = p - 1;
  for(j = p;j < r;j++){
    if ( A[j] <= x){
      i++;
      t = A[i];A[i] = A[j];A[j] = t;
    }
  }
  t = A[i + 1]; A[i +1] = A[r];A[r] = t;
  return i + 1;
}

int main(){
  int i,q;

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

  q = partition(0,n - 1);

  for(i = 0; i < n;i++){
    if(i)printf(" ");
    if( i == q)printf("[");
    printf("%d", A[i]);
    if( i == q)printf("]");
  }
  printf("\n");

  return 0;
}
   
      
        



Measured memory_bytes: 2244
#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>
using namespace std;

#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"

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

const long long MOD = 1e9+7;

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

int main() {
    string s, t;
    cin >> s >> t;
    int q;
    cin >> q;
    
    int l = s.size(), m = t.size();
    
    vector<vector<int>> s_sum(2, vector<int>(l + 1)), t_sum(2, vector<int>(m + 1));
    rep(i, 2) rep(j, l) s_sum[i][j + 1] = s_sum[i][j] + (s.at(j) == 'A' + i);
    rep(i, 2) rep(j, m) t_sum[i][j + 1] = t_sum[i][j] + (t.at(j) == 'A' + i);
    
    rep(_q, q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; c--;
        
        int sa = s_sum[0][b] - s_sum[0][a], sb = s_sum[1][b] - s_sum[1][a];
        int ta = t_sum[0][d] - t_sum[0][c], tb = t_sum[1][d] - t_sum[1][c];
        
        if ((-sa + sb + ta - tb) % 3 == 0) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

Measured memory_bytes: 2808
n = int(input())
shiritori = []
for _ in range(n):
    shiritori.append(input())

if len(set(shiritori)) != n:
    print ("No")
    exit ()

for i in range(n-1):
    if shiritori[i][-1] != shiritori[i+1][0]:
        print ("No")
        exit ()
else:
    print ("Yes")


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>

int up(void *a , void *b){
  return *(int *)a - *(int *)b;
}

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

  int a[n] , b[n];
  for(int i = 0;i < n;i ++){
    scanf("%d",&a[i]);
    b[i] = a[i];
  }

  qsort(a,n,sizeof(int),up);
  int dai = a[n/2] , syo = a[n/2 -1];
  
  for(int i = 0;i < n;i ++){
    if(b[i] >= dai){
      printf("%d\n",syo);
    }
    else if(b[i] <= syo){
      printf("%d\n",dai);
    }
  }
   return 0;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 1e3+5;

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	cin >> n;
	bool a[n][10];
	int cost[n][11];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 10; j++)
			cin >> a[i][j];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 11; j++)
			cin >> cost[i][j];
	}
	ll ans = -2e18;
	for (int mask = 1; mask < (1 << 10); mask++)
	{
		ll val = 0;
		for (int i = 0; i < n; i++)
		{
			int ind = 0;
			for (int j = 0; j  < 10; j++)
			{
				if ((mask >> j & 1) && a[i][j])
					ind++;
			}
			val += cost[i][ind];
		}
		ans = max(ans, val);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#終了判定は　持ちこまがp-1であれば終われる。

"""
アルゴリズム

handstone : それぞれ候補者の持ちコマ リストで候補者はindexで member = 0~n-1まで存在
allstone : 現在のお椀のコマ

作るべき機能:

1. 
まず、現在のトリ役の手持ちをチェック　もし、お椀の中身が１個で、かつ持っている個数がp-1 であれば、breakして終了



お椀の中身をチェック
"""

while(True):

	n, p= input().split()
	
	if n =='0' and p =='0':
		break
	n = int(n) #n人
	p = int(p)
	allstone = int(p) #椀の石の数
	
	handstone = []
	for i in range(n):
		handstone.append(0)
	
	member = 0
	
	while(True):
			
		if member == n:
			member = 0
			
		if handstone[member] == p-1 and allstone == 1: #ほかの人が全く石を持っていない
				print(member)
				break
		
	
		if allstone == 0: #椀の中に石がない場合、戻そう
			allstone += handstone[member] 
			handstone[member] = 0
		else:
			handstone[member] += 1
			allstone -= 1
			
		member += 1
	



Measured memory_bytes: 5608
#![allow(dead_code)]
use std::cmp;
use std::collections::*;

pub struct Scanner {
    bytes: Vec<u8>,
    begin: usize,
    end: usize,
}

impl Scanner {
    pub fn new() -> Self {
        let mut buffer: Vec<u8> = Vec::new();
        std::io::Read::read_to_end(&mut std::io::stdin(), &mut buffer).unwrap();
        let end = (0..)
            .find(|i| *i == buffer.len() || buffer[*i].is_ascii_whitespace())
            .unwrap();
        Scanner {
            bytes: buffer,
            begin: 0,
            end: end,
        }
    }
    pub fn next<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let s: &str = unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
        let ret: T = s.parse::<T>().unwrap();
        self.skip();
        ret
    }
    pub fn next_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }
    pub fn next_word(&mut self) -> Vec<u8> {
        let r = Vec::from(&self.bytes[self.begin..self.end]);
        self.skip();
        r
    }
    fn skip(&mut self) {
        self.begin = (self.end..)
            .find(|i| *i == self.bytes.len() || !self.bytes[*i].is_ascii_whitespace())
            .unwrap();
        self.end = (self.begin..)
            .find(|i| *i == self.bytes.len() || self.bytes[*i].is_ascii_whitespace())
            .unwrap();
    }
}

fn lower_bound<T: std::cmp::Ord>(v: &Vec<T>, val: &T) -> usize {
    let mut lb: isize = -1;
    let mut ub: isize = v.len() as isize;
    while ub - lb > 1 {
        let mid = (lb + ub) / 2;
        if *val <= v[mid as usize] {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    return ub as usize;
}

fn dfs(
    u: usize,
    p: usize,
    dp: &mut Vec<i32>,
    ans: &mut Vec<usize>,
    a: &Vec<i32>,
    edge: &Vec<Vec<usize>>,
    pans: usize,
) {
    let idx = lower_bound(dp, &a[u]);
    let prev = dp[idx];
    ans[u] = if dp[idx] == i32::max_value() {
        pans + 1
    } else {
        pans
    };
    dp[idx] = a[u];

    for v in &edge[u] {
        if *v == p {
            continue;
        }
        dfs(*v, u, dp, ans, a, edge, ans[u]);
    }
    dp[idx] = prev;
}

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let a: Vec<i32> = scan.next_vec(n);
    let mut edge: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let u: usize = scan.next();
        let v: usize = scan.next();
        let (u, v) = (u - 1, v - 1);
        edge[u].push(v);
        edge[v].push(u);
    }
    let mut dp: Vec<i32> = vec![i32::max_value(); n];
    let mut ans: Vec<usize> = vec![0; n];
    dfs(0, 0, &mut dp, &mut ans, &a, &edge, 0);
    for x in ans {
        println!("{}", x);
    }
}


Measured memory_bytes: 39220
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
long dp[105][100005];
long w[100005];
long val[100005];
int n;
long knap(int i,int W){
	if(i == n || W == 0)
		return 0;
	if(dp[i][W]!=-1)
		return dp[i][W];
	if(w[i]>W)
		return knap(i+1,W);
	else
		return dp[i][W] = max(knap(i+1,W-w[i]) + val[i],knap(i+1,W));

}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE    
    freopen("input.txt", "r", stdin);     
    freopen("output.txt", "w", stdout);
#endif
int W;
cin>>n>>W;

	rep(i,n){
		cin>>w[i];
		cin>>val[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<knap(0,W);
 
 
 
 
 
 
 
 

 
return 0;
}

Measured memory_bytes: 85660
#include<iostream>

using namespace std;

int main() {
	int i, j, W, H;
	while (cin >> H >> W, H || W){
		for (i = 1; i <= H; i++){
			for (j = 1; j <= W; j++){
				cout << "#";
			}
			cout << endl;
		}
          cout << endl;
	}
}

Measured memory_bytes: 1156
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
//R 82 L 76
	static int v[]=new int[501];
	static long D=0;
	public static void main(String[] args) {
			int a=sc.nextInt();
			int b=sc.nextInt();
			int c=sc.nextInt();
			int d=sc.nextInt();
			while(true) {
				c-=b;
				if(c<=0) {
					p("Yes");
					break;
				}
				a-=d;
				if(a<=0) {
					p("No");
					break;
				}
			}
			
			//String S=sc.next();
			
			//int a[]=new int[N];
			//for(int i=0;i<N;i++) {}
	}
	/*static boolean v(int i,long sum1,long sum2) {
		if(i==N) {
			long b=Math.abs(sum1-sum2);
			if(b==0) {
				if(sum1<=K) {
					return true;
				}else return false;
			}else if(b%D==0) {
				if(Math.max(sum1, sum2)<=K)return true;
				else return false;
			}
			else return false;
		}
		
		if(v(i+1,sum1,sum2+v[i]%D))return true;
		
		if(v(i+1,sum1+D-v[i]%D,sum2))return true;
		return false;
		
	}*/
	
	
	
	//static int memo[][]=new int[501][1000];
	

	

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 35780
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = n-1; i >= 0; i--) {
			a[i] = sc.nextInt();
		}
		for(int j = 0; j < n; j++) {
			System.out.print(a[j]);
			if(j==n-1)break;
			System.out.print(" ");
		}
		System.out.println();
		
		
		sc.close();
	}
}


Measured memory_bytes: 26320
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int h1, h2, m1, m2, k, ans;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  ans = (h2 - h1)*60 + m2 - m1 - k;
  cout << ans << endl;
  
return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>


     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define sz size()
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

     
const ll MOD = 1e9 + 7;
const ll ZER = 0;



int main(){
    int n;
    cin >> n;
    int cnt = 0;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        if(a == b)cnt++;
        else cnt = 0;
        if(cnt >= 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}





Measured memory_bytes: 3588
n, m = map(int, input().split())

lab = [[] for _ in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    lab[a].append(b)
    lab[b].append(a)

l = [0]*(n+1)
num = [1]

while num:
    v = num.pop(0)
    for i in lab[v]:
        if not l[i]:
            l[i] = v
            num.append(i)
            
if not 0 in l[2:]:
    print("Yes")
    for i in range(2, n+1):
        print(l[i])
else:
    print("No")


Measured memory_bytes: 34028
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main(void)
{
    int n; cin >> n;
    int tmp;
    if (n % 1000 == 0) tmp = n / 1000;
    else tmp = n / 1000 + 1;
    int ret = tmp * 1000 - n;
    cout << ret << endl;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String args[]){
		
		Scanner cin = new Scanner(System.in);
		
		String A = cin.next();
		int lenA = A.length();
		String B = cin.next();
		int lenB = B.length();
		String C = cin.next();
		cin.close();
		String result = "YES";
		
		if(A.charAt(lenA-1)==B.charAt(0)&&B.charAt(lenB-1)==C.charAt(0)){
			
		}else{
			result = "NO";
		}
		
		System.out.println(result);
	}
}


Measured memory_bytes: 23892
// <------------- Template -----------------------> //

/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
*/

#pragma optimization_level 3   									//Comment optimisations for an interatcive problem - use endl
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

// <------------- Declare Variables Here ------------> //

ll a,b;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

int main() {
	fastio;
	cin>>a>>b;
	if(a>b) for(ll i=0;i<a;i++) cout<<b;
	else    for(ll i=0;i<b;i++) cout<<a;
	newl;
	return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pi;

int n, m;
ll k;

const int maxn = 1005;
const int mod = 1e9 + 7;

char s[maxn][maxn], t[maxn][maxn];

void add(int &a, int b){
    a += b;
    if(a >= mod)
        a -= mod;
}

struct matrix{
    int a[2][2];
    matrix(){ memset(a, 0, sizeof(a));}
    matrix operator * (const matrix & rhs) const{
        matrix ret;
        for(int i = 0;i < 2;i++){
            for(int j = 0;j < 2;j++){
                for(int k = 0;k < 2;k++){
                    add(ret.a[i][k], 1LL * a[i][j] * rhs.a[j][k] % mod);
                }
            }
        }
        return ret;
    }
};

matrix qpow(matrix a, ll n){
    matrix ret;
    for(int i = 0;i < 2;i++){
        ret.a[i][i] = 1;
    }
    while(n > 0){
        if(n & 1){
            ret = ret * a;        
        }
        a = a * a;
        n >>= 1;
    }
    return ret;
}

int qpow(int a, ll n){
    int ret = 1;
    while(n > 0){
        if(n & 1){
            ret = 1LL * ret * a % mod;
        }
        a = 1LL * a * a % mod;
        n >>= 1;
    }
    return ret;
}

int main(){
    cin >> n >> m >> k;
    for(int i = 0;i < n;i++){
        scanf("%s", s[i]);
    } 
    bool row = false, col = false;
    for(int i = 0;i < n;i++){
        if(s[i][0] == '#' and s[i][m - 1] == '#'){
            row = true;
        }
    }
    for(int j = 0;j < m;j++){
        if(s[0][j] == '#' and s[n - 1][j] == '#'){
            col = true;
        }
    }
    int black = 0;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            if(s[i][j] == '#')
                black++;
        }
    }
    if(row and col){
        cout << 1 << endl;
    }else if(!row and !col){
        if(k == 0){
            cout << 1 << endl;
        }else{
            cout << qpow(black, k - 1) << endl;
        }
    }else{
        if(col){
            for(int i = 0;i < n;i++){
                for(int j = 0;j < m;j++){
                    t[i][j] = s[i][j];
                }
            }
            for(int i = 0;i < n;i++){
                for(int j = 0;j < m;j++){
                    s[j][i] = t[i][j];
                }
            }
            swap(n, m);
        }
        int c = 0;
        int b = 0;
        for(int i = 0;i < n;i++){
            if(s[i][0] == '#' and s[i][m - 1] == '#'){
                c++;
            }
            for(int j = 0;j < m - 1;j++){
                if(s[i][j] == '#' and s[i][j + 1] == '#'){
                    b++;
                }
            }
        }
        matrix a;
        //cout << black << " " << b << " " << c << endl;
        a.a[0][0] = black;
        a.a[0][1] = (mod - b) % mod;
        a.a[1][1] = c;
        a = qpow(a, k - 1);
        cout << (a.a[0][0] + a.a[0][1]) % mod << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
H,W = map(int,input().split())
a=[]
for i in range(H):
  tmp=input()
  if tmp.count("#")==0:
    pass
  else:
    a.append(list(tmp))
else:
  H=len(a)
#print(a)
  
Ignore_tate = []
#たてNGリストアップ
for j in range(W):
  flag=True #除外対象である
  for k in range(H):
    if a[k][j]=="#":
      flag=False
      break
  if flag:
    Ignore_tate.append(j)

for p in range(H):
  str=""
  for q in range(W):
    if q not in Ignore_tate:
      str += a[p][q]
  print(str)

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(a+c==2*b)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
  int n;  cin>>n;
  vector<ll> a(n);
  rep(i,0,n){
    cin >> a[i];
  }
  deque<ll> que;
  int rev=1;
  rep(i,0,n){
    if(rev){
      que.push_back(a[i]);
    }else{
      que.push_front(a[i]);
    }
    rev = 1-rev;
  }
  if(!rev){
    reverse(all(que));
  }
  rep(i,0,n){
    cout << que.front() << " ";
    que.pop_front();
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>
#include <stdlib.h>

int parent(int);
int left(int);
int right(int);

int main(){
  int h,l,r,*A;
  int i;

  scanf("%d",&h);
  A = (int *)malloc(sizeof(int)*(h+1));
  for(i=1;i<=h;i++){
    scanf("%d",&A[i]);
  }

  for(i=1;i<=h;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i!=1) printf("parent key = %d, ",A[parent(i)]);
    if((l=left(i)) <= h) printf("left key = %d, ",A[l]);
    if((r=right(i)) <= h) printf("right key = %d, ",A[r]);
    printf("\n");
  }

  return 0;
}

int parent(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}

Measured memory_bytes: 600
S = str(input())

if S[:7] == "keyence" or S[-7:] == "keyence":
    print("YES")
    exit()

elif S[:1] + S[-6:] == "keyence" or S[:2] + S[-5:] == "keyence" or S[:3] + S[-4:] == "keyence" or S[:4] + S[-3:] == "keyence" or S[:5] + S[-2:] == "keyence" or S[:6] + S[-1:] == "keyence":
    print("YES")
    exit()

else:
    print("NO")


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

bool visr[12], visc[12];
int cnt[26], n, m, row[12], col[12];
string s[12]; 

bool EqualCol(int x, int y) {
  memset(cnt, 0, sizeof(cnt));
  for(int i = 0; i < n; i++)
    cnt[(int)(s[i][x] - 'a')]++,
      cnt[(int)(s[i][y] - 'a')]--;
  for(int i = 0; i < 26; i++)
    if(cnt[i]) return 0;
  return 1;
}

bool EqualRow(int x, int y) {
  memset(cnt, 0, sizeof(cnt));
  for(int i = 0; i < m; i++)
    cnt[(int)(s[x][i] - 'a')]++,
      cnt[(int)(s[y][i] - 'a')]--;
  for(int i = 0; i < 26; i++)
    if(cnt[i]) return 0;
  return 1;
}

bool Check(void) {
  //cerr << "!" << endl;
  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++)
      if(s[row[i]][col[j]] != s[row[n - i - 1]][col[m - j - 1]]) return 0;
  return 1;
}

bool SolveCol(int x) {
  //cerr << "!" << " " << x << endl;
  if(x == (m + 1) / 2) return Check();
  if((m & 1) && (x == m / 2)) {
    for(int i = 0; i < m; i++)
      if(!visc[i])
	col[x] = i;
    return SolveCol(x + 1);
  }
  for(int i = 0; i < m; i++)
    if(!visc[i])
      for(int j = i + 1; j < m; j++)
	if(!visc[j] && EqualCol(i, j)) {
	  visc[j] = visc[i] = 1;
	  col[x] = i;
	  col[m - x - 1] = j;
	  if(SolveCol(x + 1)) return 1;
	  visc[j] = visc[i] = 0;
	}
  return 0;
}

bool SolveRow(int x) {
  if(x == (n + 1) / 2) return SolveCol(0);
  if((n & 1) && (x == n / 2)) {
    for(int i = 0; i < n; i++)
      if(!visr[i])
	row[x] = i;
    return SolveRow(x + 1);
  }
  for(int i = 0; i < n; i++)
    if(!visr[i]) 
      for(int j = i + 1; j < n; j++)
	if(!visr[j] && EqualRow(i, j)) {
	  visr[i] = visr[j] = 1;
	  row[x] = i;
	  row[n - x - 1] = j;
	  if(SolveRow(x + 1)) return 1;
	  visr[i] = visr[j] = 0;
	} 
  return 0;
}

int main(void) {
  scanf("%d%d", &n, &m);
  for(int i = 0; i < n; i++) {
    cin >> s[i];
  }
  puts(SolveRow(0) ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main( ){

  int x,y;
 
  for ( ; ; ) {
    cin >> x >> y;
    if (x == 0 && y == 0 ) break;
    if( x < y ){
      cout << x << " " << y <<endl;
    }
    else{
      cout << y << " " << x <<endl;
    }
  }
 return 0;
}

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

int main()
{
	char s[100001];
	scanf("%s", s);

	bool flag = false;
	long long count = 0;
	long long n = strlen(s);
	for (int i = 0; i < n; i++)
	{
		const bool bit = (s[i] != '0');
		if (bit != flag)
		{
			count++;
		}

		flag = !flag;
	}

	count = std::min(count, n - count);
	printf("%lld\n", count);
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        sc.close();

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) {
                continue;
            }
            int max = h[i];
            for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            }
        }
        System.out.println(ans);
    }

}


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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

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

    ll ans = 0;
    for(auto p : m){
        if(p.first != p.second){
            if(p.second > p.first){
                ans += p.second - p.first;
            }else{
                ans += p.second;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6272
s = list(input())
n = len(s)
flag = 1
c = int((n - 1) / 2)

for i in range(c):
    if s[i] != s[n - 1 - i]:
        flag = 0
        break

if flag:
    c2 = int(c / 2)
    for i in range(c2):
        if s[i] != s[c - 1 - i]:
            flag = 0
            break

if flag:
    print('Yes')
else :
    print('No')

Measured memory_bytes: 3064
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  const [diceA, diceB] = content
    .trim()
    .split('\n')
    .map(line => line.split(' ').map(n => parseInt(n, 10)))
    .map(nums => createDice(nums));

  console.log(isSameDice(diceA, diceB) ? 'Yes' : 'No');
});

const isSameDice = (diceA, diceB) => {
  const timeout = Date.now() + 400;
  while (Date.now() < timeout) {
    const dirs = ['N', 'W', 'S', 'E'];
    const dir = dirs[Math.floor(Math.random() * dirs.length)];
    diceA = roll(diceA, dir);
    const isSame = diceA.right.every((n, i) => n === diceB.right[i]) && diceA.top.every((n, i) => n === diceB.top[i]);
    if (isSame) {
      return true;
    }
  }

  return false;
};

const resolve = (dice, [top, front]) => {
  const dirs = ['N', 'W', 'S', 'E'];
  while (dice.top[0] !== top || dice.top[3] !== front) {
    const dir = dirs[Math.floor(Math.random() * dirs.length)];
    dice = roll(dice, dir);
  }

  return dice;
};

const createDice = nums => ({
  top: [1, 5, 6, 2].map(n => nums[n - 1]),
  right: [1, 3, 6, 4].map(n => nums[n - 1]),
});

const roll = (dice, dir) => {
  switch (dir) {
    case 'W': {
      return Object.assign({}, dice, {
        top: [dice.right[1], dice.top[1], dice.right[3], dice.top[3]],
        right: dice.right.slice(1).concat([dice.right[0]]),
      });
    }
    case 'E': {
      return Object.assign({}, dice, {
        top: [
          dice.right[dice.right.length - 1],
          dice.top[1],
          dice.right[1],
          dice.top[3],
        ],
        right: [dice.right[3]].concat(dice.right.slice(0, -1)),
      });
    }
    case 'S': {
      return Object.assign({}, dice, {
        top: dice.top.slice(1).concat([dice.top[0]]),
        right: [dice.top[1], dice.right[1], dice.top[3], dice.right[3]],
      });
    }
    case 'N': {
      return Object.assign({}, dice, {
        top: [dice.top[3]].concat(dice.top.slice(0, -1)),
        right: [dice.top[3], dice.right[1], dice.top[1], dice.right[3]],
      });
    }
  }
};


Measured memory_bytes: 19736
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const LL mod=1e9+7;
char s[100010];LL n;
LL f[4][100010];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	f[3][n+1]=1;
	for(LL i=n;i>=1;i--)
	{
		if(s[i]=='?')
		{
			f[0][i]=(f[0][i+1]*3+f[1][i+1])%mod;
			f[1][i]=(f[1][i+1]*3+f[2][i+1])%mod;
			f[2][i]=(f[2][i+1]*3+f[3][i+1])%mod;
			f[3][i]=(f[3][i+1]*3)%mod;
		}
		if(s[i]=='A')
		{
			f[0][i]=(f[0][i+1]+f[1][i+1])%mod;
			f[1][i]=(f[1][i+1])%mod;
			f[2][i]=(f[2][i+1])%mod;
			f[3][i]=(f[3][i+1])%mod;
		}
		if(s[i]=='B')
		{
			f[0][i]=(f[0][i+1])%mod;
			f[1][i]=(f[1][i+1]+f[2][i+1])%mod;
			f[2][i]=(f[2][i+1])%mod;
			f[3][i]=(f[3][i+1])%mod;
		}
		if(s[i]=='C')
		{
			f[0][i]=(f[0][i+1])%mod;
			f[1][i]=(f[1][i+1])%mod;
			f[2][i]=(f[2][i+1]+f[3][i+1])%mod;
			f[3][i]=(f[3][i+1])%mod;
		}
	}
	printf("%lld\n",f[0][1]);
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);++i)
#define rep1(i, n) for(int i=1;i<=(int)(n);++i)
#define irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for(int i=(int)(n);i>=1;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


int main (void)
{
  int n; cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  cout<<(count_if(all(a),[](int x){return x%2 == 1;}) != 0 ? "first" : "second")<<endl;
  return 0;
}


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

ans =1000000
tmp_ans = 0
for i in range(n):
  while a[i]%2==0:
    a[i]=a[i]//2
    tmp_ans +=1
  ans = min(ans,tmp_ans)
  tmp_ans=0
  
print(ans)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String word = null;
		String mStr = null;
		int count = 0;
		Map<Integer, String> map = new HashMap<>();
		
		while (true) {
			try {
				word = br.readLine();

				if ("-".equals(word)) {
					break;
				}
				mStr = br.readLine();
				int m = Integer.parseInt(mStr);
				for (int i = 0; i < m; i++) {
					int h = Integer.parseInt(br.readLine());
					word = word.substring(h, word.length()) + word.substring(0, h);
				}
				map.put(count, word);
				count++;
				
			} catch (IOException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			} 
		}
		
		for (Map.Entry<Integer, String> entry: map.entrySet()) {
			System.out.println(entry.getValue());
		}

	}

}



Measured memory_bytes: 24508
#include<bits/stdc++.h>
// Begin Header {{{
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const double PI = acos(-1);
using namespace std;
using Graph = vector<vector<lli>>;
using P = pair<int, int>;
// }}} End Header

int main(){
	string s;
	cin >> s;
	cout << "ABC" << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;

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



int main(){
    int n, q;
    string s;
    cin>>n>>q>>s;
    vector<int> sum(n+1, 0);
    for(int i=1; i<=n; i++){
        sum[i+1]=sum[i];
        if(s[i-1]=='A'&&s[i]=='C'){
            sum[i+1]++;
        }
    }
    for(int i=0; i<q; i++){
        int l, r;
        cin>>l>>r;
        cout<<sum[r]-sum[l]<<endl;
    }
    
}


Measured memory_bytes: 1408
n,a,b,c,d=map(int,input().split())

s=input()

if c<d:
    p=s[a:d-1].count("##")
    if p==0:
        print("Yes")
    else:
        print("No")
else:
    p=s[a:c-1].count("##")
    q=s[b-2:d+1].count("...")
    if p==0 and q>0:
        print("Yes")
    else:
        print("No")
        
        

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int l = 16 - (a+b);
		int max = Math.max(a, b);
		int min = Math.min(a, b);
		System.out.println(max <= min + l ? "Yay!" : ":(");
	}
}

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

#define int long long
#define INT int
#define rep(i, n) for (int i = 0; i < (n); i++)

int t_index[200005];
string s;

int cToi(char x)
{
    return x - '0';
}

signed main()
{
    cin >> s;

    int len = s.size();
    if (len < 4)
    {
        cout << "0" << endl;
        return 0;
    }

    reverse(s.begin(), s.end());
    int x = 1, tot = 0;
    vector<int> cnt(2019);
    int ans = 0;
    rep(i, len)
    {
        cnt[tot]++;
        tot += (s[i] - '0') * x;
        tot %= 2019;
        ans += cnt[tot];
        x = x * 10 % 2019;
    }

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


Measured memory_bytes: 3756
// #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>

#include <bitset>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repr(i,n) for (int i = 0; i < (f); --i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MAX = 100;
const int INF = (1<<12);

int main() {
  int n;
  cin >> n;
  int ans = 128;
  string s = bitset<7>(n).to_string();
  for(string::iterator it = s.begin(); it!=s.end(); ++it){
    ans /= 2;
    if(*it == '1'){
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b,c,x,s;
main(){
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)for(int k=0;k<=c;k++)s+=i*500+j*100+k*50==x;
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
 
int arr[222222];
lld ans = 0;
int main(void){
	int n,p;
	scanf("%d%d",&n,&p);
	arr[0] = 1;
	for(int e=1;e<n;e++) arr[e] = (arr[e-1]*10)%p;
	string a;
	cin >> a;
	reverse(a.begin(),a.end());
	if(p==2||p==5){
		lld ans = 0;
		for(int e=(int)a.size()-1;e>=0;e--){
			int diff = (int)a.size() - e;
			if((int)(a[e]-'0')%p==0){
				ans += (lld)diff;
			}	
		}
		printf("%lld",ans);
		return 0;
	}
	int val = 0,num = 0,vis[11111];
	memset(vis,0,sizeof(vis));
	vis[0] = 1;
	for(int q=0;q<n;q++){
		val = (val+((int)(a[q]-'0')*arr[q]))%p;
		ans += vis[val];
		vis[val]++;
 	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1412
a,b,c = gets.chomp.split.map(&:to_i)

result = false

if b-a > 0 && c-a > 0 
   result = true if b-c > 0
elsif b-a < 0 && c-a < 0
   result = true if b-c < 0
end

puts result ? "Yes" : "No"

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%d\n",n)
#define pff(a,b) printf("%d  %d\n",a,b);
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	int a;
	cin >> a;
	if (400 <= a && a <= 599) {
		pf(8);
	}
	else if (600 <= a && a <= 799) {
		pf(7);
	}
	else if (800 <= a && a <= 999) {
		pf(6);
	}
	else if (1000 <= a && a <= 1199) {
		pf(5);
	}
	else if (1200 <= a && a <= 1399) {
		pf(4);
	}
	else if (1400 <= a && a <= 1599) {
		pf(3);
	}
	else if (1600 <= a && a <= 1799) {
		pf(2);
	}
	else if (1800 <= a && a <= 1999) {
		pf(1);
	}

	return 0;
}

Measured memory_bytes: 3760
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int N, X;
  int L[100];
  int K =0;

  scanf("%d %d\n",&N, &X );

  for ( int i = 0; i < N; i++) {
    scanf("%d",&L[i] );
  }

  for (int i = 0; i < N; i++) {
    K += L[i];
    if(K>X){
      printf("%d",i+1 );
      break;
    }else if(K ==X){
      printf("%d",i+2 );
      break;
    }
    if(i==N-1){
      printf("%d",i+2 );
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 128
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

for i in range(n):
    p[i] -= 1
def score(a, k):
    now = p[a]
    s = c[now]
    cnt = 1
    l = [s]
    while now != a and cnt < k:
        now = p[now]
        s += c[now]
        l.append(s)
        cnt += 1
    if cnt == k:
        return max(l)
    l.append((k // cnt - 1) * s + max(l))
    s = (k // cnt) * s
    k %= cnt
    cnt=0
    while cnt < k:
        now = p[now]
        s += c[now]
        l.append(s)
        cnt += 1
    return max(l)
print(max(score(i, k) for i in range(n)))


Measured memory_bytes: 111772
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int main (void)
{
	int c[4][4];
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
			cin>>c[i][j];
	for(int i=-5000;i<=5000;i++)
	{
		bool flag = true;
		int a1 = i;
		int b1 = c[1][1] - a1;
        int b2 = c[1][2] - a1;
        int b3 = c[1][3] - a1;
        int a2 = c[2][1] - b1;
        int a3 = c[3][1] - b1;
        if(c[2][2] != a2 + b2||c[2][3] != a2 + b3||c[3][2] != a3 + b2||c[3][3] != a3 + b3)
        	flag = false;
        if(flag)
        {
        	cout<<"Yes"<<endl;
        	return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    string s[110];
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<2;j++){
        cout <<s[i]<<endl;
        }
    }
    
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int a, b, c; cin >> a >> b >> c;
    if(a == b) cout << c << endl;
    else if (b == c) cout << a << endl;
    else cout << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

int main() {
    Bint x, k, d;
    cin >> x >> k >> d;
    if(x == 0){
        if(k % 2 == 0) cout << 0 << endl;
        else cout << d << endl;
        return 0;
    }
    if(x>0){
        if(x-d*k>0){
            cout << x-d*k << endl;
            return 0;
        }else if(x-d*k==0){
            cout << 0 << endl;
            return 0;
        }else{
            if((k-x/d)%2 == 0) cout << x%d << endl;
            else cout << abs(x%d-d) << endl;
            return 0;
        }
    }else{
        if(x+d*k<0){
            cout << abs(x+d*k) << endl;
            return 0;
        }else if(x+d*k==0){
            cout << 0 << endl;
            return 0;
        }else{
            if((k-(-x)/d)%2 == 0) cout << (-x)%d << endl;
            else cout << abs((-x)%d-d) << endl;
            return 0;
        }
    }
    return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Trim();

        var t = s.Select(x => x == 'R' ? 0 : x == 'G' ? 1 : 2).ToArray();

        var sum = new int[3][];
        for (int i = 0; i < sum.Length; ++i)
        {
            sum[i] = new int[t.Length + 1];
        }
        for (int i = 0; i < t.Length; ++i)
        {
            for (int j = 0; j < sum.Length; ++j)
            {
                sum[j][i + 1] = sum[j][i];
            }
            ++sum[t[i]][i + 1];
        }

        var count = 0L;
        for (int i = 0; i < t.Length; ++i)
        {
            for (int j = i + 1; j < t.Length; ++j)
            if (s[i] != s[j])
            {
                // (0, 1) -> 2, (1, 2) -> 0, (2, 0) -> 1
                var c = sum.Length - (t[i] + t[j]);
                var k = j + (j - i);
                count += sum[c].Last() - sum[c][j + 1] - (k < t.Length && t[k] == c ? 1 : 0);
            }
        }

        Console.WriteLine(count);
    }
}


Measured memory_bytes: 28428
#include<iostream>
#include<vector>

int main(){
	int n;
	std::cin >> n;
	std::vector<int> count(n);
	for(int i=0; i<n-1; i++){
		int joushi;
		std::cin >> joushi;
		--joushi;
		count[joushi]++;
	}
	for(int i=0; i<n; i++){
		std::cout << count[i] << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int a, b;
  string str;
  cin >> a >> b >> str;
  smatch smatch;
  if (regex_search(str, smatch,
      regex("^\\d{" + to_string(a) + "}-\\d{" + to_string(b) + "}$"))) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(T: int, X: int):
    print(T / X)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    T = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(T, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
#define ALL(a)  (a).begin(),(a).end()
const int MOD = 1000000007;
int main() {
	ll k;cin >> k; queue<ll> q;
	rep(i, 9) q.push(i + 1);
	rep(i, k - 1) {
		ll j = q.front(); q.pop();
		rep(i,10){
			if (abs(i - j % 10) <= 1) {
				q.push(j * 10 + i);
			}
		}
	}
	cout << q.front() << endl;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<pair<int64_t, int64_t>> ab(m);
    for (auto i : irange(0L, m)) {
        cin >> ab[i].first >> ab[i].second;
    }

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

    int64_t ans = 0;
    int64_t p = n;
    for (const auto& t : ab | reversed) {
        if (p < t.second) {
            continue;
        }

        ++ans;
        p = t.first;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792