akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.*;

public class Main {
	 static InputReader in = new InputReader(System.in);
	 static PrintWriter out = new PrintWriter(System.out);
	 
	 public static void main(String[] args) {
		 int n = in.nextInt();
		 int count = 0;
		 Map<Long,Integer> map = new HashMap<>();
		 long a =0;
		 while (n -- >0)
		 {
			 a=in.nextLong();
			 map.put(a,map.getOrDefault(a,0)+1);
		 }
		 
		 for (int nums:map.values())
		 {
			 if(nums%2 ==1)
				 count++;
		 }
		 
		 out.println(count);
		 out.close();
		 
		 //Arrays.asList(array).contains("x")
	 
	 }
	 static class InputReader {
	        public BufferedReader reader;
	        public StringTokenizer tokenizer;
	 
	        public InputReader(InputStream stream) {
	            reader = new BufferedReader(new InputStreamReader(stream), 32768);
	            tokenizer = null;
	        }
	 
	        public String next() {
	            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
	                try {
	                    tokenizer = new StringTokenizer(reader.readLine());
	                } catch (IOException e) {
	                    throw new RuntimeException(e);
	                }
	            }
	            return tokenizer.nextToken();
	        }
	 
	        public int nextInt() {
	            return Integer.parseInt(next());
	        }
	 
	        public long nextLong() {
	            return Long.parseLong(next());
	        }
	 
	        public double nextDouble() {
	            return Double.parseDouble(next());
	        }
	 
	        public String nextLine() {
	            try {
	                return reader.readLine();
	            } catch (Exception e) {
	                e.printStackTrace();
	            }
	            return null;
	        }
	 
	        public boolean hasNext() {
	            String next = null;
	            try {
	                next = reader.readLine();
	            } catch (Exception e) {
	            }
	            if (next == null) {
	                return false;
	            }
	            tokenizer = new StringTokenizer(next);
	            return true;
	        }
	 
	        public BigInteger nextBigInteger() {
	            return new BigInteger(next());
	        }
	    }
	}

Measured memory_bytes: 57140
#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
using namespace std;

const int maxn=1000003;

long long sum[maxn];
int n;
inline void update(int x){
	for(int i=x;i<maxn;i+=lowbit(i))
		++sum[i];
}
inline int query(int x){
	static int rt;rt=0;
	for(int i=x;i>0;i-=lowbit(i))
		rt+=sum[i];
	return rt;
}
long long KK=5e5,a[maxn],pre[maxn];
inline bool check(int x){
	static long long res;res=0;
	pre[0]=0;
	for(int i=1;i<=n;++i)
		pre[i]=pre[i-1]+(a[i]>=x?1:-1);
	memset(sum,0,sizeof(sum));
	for(int i=0;i<=n;++i){
		res+=query(pre[i]+KK);
		update(pre[i]+KK);
	}
	return res>=1ll*n*(n+1)/4;
}

int main(){
	scanf("%d",&n);
	if(n==1){
		scanf("%lld",&a[1]);
		printf("%lld\n",a[1]);
		return 0;
	}
	for(int i=1;i<=n;++i)
		scanf("%lld",&a[i]);
	int l=-1,r=1e9+7;
	while(l<r-1){
		int mid=(l+r)/2;
		if(check(mid)) l=mid;
		else r=mid;
	}
	printf("%d\n",l);
	return 0;
}


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

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

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

using namespace std;

int main(){

    long double n,d;
    cin >> d >> n;


    if(n!=100)cout << n*(pow(100,d)) << endl;
    else if(d==0) cout << 101 << endl;
    else if(d==1) cout << 10100 << endl;
    else cout << 1010000 << endl;

}

Measured memory_bytes: 256
import java.util.*;
 
class Main {
	public static void main(String[] a){
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    
     System.out.println(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5) ? "Yes" : "No");
    
    }
  
}

Measured memory_bytes: 22868
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
int n,k,c,num;
int main()
{
    cin>>n>>k;

    c = 1;
    num = 1;
    while(c != k) {
        num+=2;
        c++;
    }
    if (num <= n) {
        cout<<"YES"<<endl;
    } else
    {
        cout<<"NO"<<endl;
    }
    
    
    return 0;
}

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

signed main(void)
{
	int A, B, m;
	cin >> A >> B >> m;
	int a[A], b[B];
	int x[m], y[m], c[m];
	int ans, min_a, min_b;
	min_a = min_b = 1e9;
	rep(i, A) 
	{
		cin >> a[i];
		min_a = min(a[i], min_a);
	}
	rep(i, B)
	{
		cin >> b[i];
		min_b = min(b[i], min_b);
	}
	ans = min_a + min_b; 
	rep(i, m)
	{
		cin >> x[i] >> y[i] >> c[i];
		x[i]--; y[i]--;
		ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		
		int N = scan.nextInt();
		int M = scan.nextInt();
		int[]DN = new int[N];//一人の生徒の最小のマンハッタン距離
		int[]MN = new int[N];//一人の生徒の最小のマンハッタン距離の番号
		
		int[] a = new int[N];
		int[] b = new int[N];
		for(int i = 0;i<N;i++){
			a[i]=scan.nextInt();
			b[i]=scan.nextInt();
		}
		
		int[] c = new int[M];
		int[] d = new int[M];
		for(int i = 0;i<M;i++){
			c[i]=scan.nextInt();
			d[i]=scan.nextInt();
		}
		
		
		for(int i = 0;i<N;i++){//各生徒分繰り返す
			for(int j = 0;j<M;j++){//チェックポイントM個比較
				if(j==0){
					DN[i]=(Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j]));
					MN[i]=j+1;
				}else{
					if(DN[i]>Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j])){
						DN[i]=Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j]);
						MN[i]=j+1;//ここで配列の〇番目を一番目似合わせる
					}
				}
				
			}
		}
		
		
		
		
		
		
		for(int i =0;i<N;i++){//最後に生徒分の最小のマンハッタン距離だったチェックポイントを示す
			
			//System.out.println(DN[i]);
			System.out.println(MN[i]);
		}
		
		
		
		
		
		
		
		
	}

}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    
    for(int i = n - 1; i >= 0; i-=2)
    {
        if(i!=n-1) cout<<" ";
        cout<<a[i];
    }
    
    if(n%2==0)
    {
        for(int i = 0; i < n; i+=2)
        {
            cout<<" "<<a[i];
        }    
    }
    else
    {
        
        for(int i = 1; i < n; i+=2)
        {
            cout<<" "<<a[i];
        }
        
    }

    return 0;
}

Measured memory_bytes: 2944
import java.lang.reflect.Array;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int N = in.nextInt();
		int T = in.nextInt();
		
		int minC = 10000;
		int c = 0;
		int t = 0;
		for(int i=0; i<N; i++) {
			c = in.nextInt();
			t = in.nextInt();
			if(t<=T) {
				if(c < minC) {
					minC = c;
				}
			}
		}
		
		if(minC == 10000) {
			System.out.println("TLE");
		}else {
			System.out.println(minC);
		}
		
		in.close();
	}
}


Measured memory_bytes: 21844
#!/usr/bin/env ruby
require 'set'

n = gets.chomp.to_i

dict = Set.new
n.times do
  action, str = gets.chomp.split
  str = str.tr('ACTG', '1234').to_i
  if action[0] == 'i'
    dict << str
  else
    puts dict.include?(str) ? 'yes' : 'no'
  end
end

Measured memory_bytes: 26284
unittest
{
	assert( [ "3 5 2", "3 2 3 4", ".....", ".@..@", "..@.." ].solve == 5 );
	assert( [ "1 6 4", "1 1 1 6", "......" ].solve == 2 );
	assert( [ "3 3 1", "2 1 2 3", ".@.", ".@.", ".@." ].solve == -1 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto h = 0L;
	auto w = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s %s"( h, w, k );
	input.popFront;
	auto sy = 0L;
	auto sx = 0L;
	auto gy = 0L;
	auto gx = 0L;
	input.front.formattedRead!"%s %s %s %s"( sy, sx, gy, gx );
	auto css = new dchar[][]( h, w );
	foreach( ref cs; css )
	{
		input.popFront;
		cs = input.front.to!( dchar[] );
	}
	sy--;
	sx--;
	gy--;
	gx--;
	
	auto dsss = dijkstraGridEx( css, k, sy, sx );
	auto ans = dsss[ gy ][ gx ].reduce!min;
	return ( ans == long.max ) ? -1 : ( ans + k - 1 ) / k;
}

// 正のグリッドマップの始点指定最短経路探索（ダイクストラ法）
auto dijkstraGridEx( T, T W = '@' )( T[][] css, long k, long sy, long sx )
{
	import std.container.binaryheap;
	
	auto dsss = new long[][][]( css.length, css[ 0 ].length, 4 );
	foreach( ref dss; dsss )
	{
		foreach( ref ds; dss ) ds[] = long.max;
	}
	dsss[ sy ][ sx ][] = 0;
	auto usss = new bool[][][]( css.length, css[ 0 ].length, 4 );
	
	auto queue = heapify!( ( a, b ) => b[ 3 ] < a[ 3 ] )( new Tuple!( long, long, long, long )[ css.length * css[ 0 ].length * 4 ], 0 );
	queue.insert( tuple( sy, sx, 0L, 0L ) );
	queue.insert( tuple( sy, sx, 1L, 0L ) );
	queue.insert( tuple( sy, sx, 2L, 0L ) );
	queue.insert( tuple( sy, sx, 3L, 0L ) );
	while( !queue.empty )
	{
		auto fy = queue.front[ 0 ];
		auto fx = queue.front[ 1 ];
		auto ff = queue.front[ 2 ];
		auto fd = queue.front[ 3 ];
		queue.popFront();
		
		if( usss[ fy ][ fx ][ ff ] ) continue;
		usss[ fy ][ fx ][ ff ] = true;
		
		foreach( i, p; [ [ -1, 0 ], [ 1, 0 ], [ 0, -1 ], [ 0, 1 ] ] )
		{
			auto ty = 0L;
			auto tx = 0L;
			auto td = 0L;
			auto tf = i.signed;
			
			if( ff == tf )
			{
				// 前進
				ty = fy + p[ 0 ];
				tx = fx + p[ 1 ];
				td = fd + 1;
				
				if( ty < 0 || css.length <= ty || tx < 0 || css[ ty ].length <= tx ) continue;		// マップ外
				if( css[ ty ][ tx ] == W ) continue;												// 壁
			}
			else
			{
				// 方向転換
				ty = fy;
				tx = fx;
				td = ( fd + k - 1 ) / k * k;
			}
			
			if( dsss[ ty ][ tx ][ tf ] <= td ) continue;
			
			dsss[ ty ][ tx ][ tf ] = td;
			queue.insert( tuple( ty, tx, tf, td ) );
		}
	}
	return dsss;
}


Measured memory_bytes: 315920
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<climits>
#include<queue>
#include<set>
#include<cmath>
#include<map>
#include<bitset>
#include<fstream>
#include<tr1/unordered_map>

typedef long long LL;
using namespace std;
#define pb push_back
#define x first
#define y second

void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

int read()
{
	int x = 0, f = 1; int c = getchar();
	while(!isdigit(c)) { if(c == '-') f = 0; c = getchar(); }
	while(isdigit(c)) { x = (x * 10) + (c ^ 48); c = getchar(); }
	return f ? x : -x;
}

const int maxn = 310;
int n, K, mod;
int f[maxn][maxn], g[maxn][maxn][maxn];

void sol1()
{
	K >>= 1; f[0][0] = 1;
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 0; j <= K; ++j)
			(f[i][0] += f[i - 1][j]) %= mod;
		for(int j = 0; j < K; ++j)
			(f[i][j + 1] += f[i - 1][j]) %= mod;
	}
	int ans1 = 0, ans2 = 0;
	for(int i = 0; i <= K; ++i) (ans1 += f[n / 2][i]) %= mod;
	for(int i = 0; i <= K; ++i) (ans2 += f[(n + 1) / 2][i]) %= mod;
	printf("%d\n", (LL)ans1 * ans2 % mod);
}

void sol2()
{
	g[0][0][0] = 1;
	for(int i = 2; i - K <= n; i += 2)
	{
		for(int j = 0; j <= n; ++j)
			for(int k = 0; k <= K + 1; ++k)
				(g[i][0][0] += g[i - 2][j][k]) %= mod;
		if(i <= n)
			for(int j = 0; j <= n; ++j)
				for(int k = 0; k <= K + 1; ++k)
					(g[i][j + 1][0] += g[i - 2][j][k]) %= mod;
		if(i - K >= 1)
			for(int j = 0; j <= n; ++j)
			{
				for(int k = 1; k <= K; ++k)
					(g[i][0][k + 1] += g[i - 2][j][k]) %= mod;
				(g[i][0][0] += g[i - 2][j][0]) %= mod;
			}
		if(i <= n && i - K >= 1)
			for(int j = 0; j <= n; ++j)
				for(int k = 0; max(k, j + 1) <= K; ++k)
					(g[i][j + 1][max(k + 1, j + 2)] += g[i - 2][j][k]) %= mod;
	}
	int p = n + K - ((n + K) & 1), ans = 0;
	for(int j = 0; j <= n; ++j)
		for(int k = 0; k <= K + 1; ++k)
			(ans += g[p][j][k]) %= mod;
	cout << ans << endl;
}

int main()
{

	n = read(), K = read(); mod = read();
	if(!(K & 1)) sol1();
	else sol2();

	return 0;
}

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

#define endl "\n"
#define ll 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 f first
#define s second
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	ll n;
	cin>>n;
	ll arr[n];
	ll mean1,mean2,sum=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	mean1 = sum/n;
	mean2 = sum/n +1;

	ll ans1=0,ans2=0;
	for (int i = 0; i < n; ++i)
	{
		ans1+= (arr[i]-mean1)*(arr[i]-mean1);
		ans2+= (arr[i]-mean2)*(arr[i]-mean2);
	}

	cout<<min(ans1,ans2);


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N, M; cin >> N >> M;
    vector<vector<int>> S;
    rep (i, 0, M) {
        vector<int> s;
        int k; cin >> k;
        rep (j, 0, k) {
            int in; cin >> in; --in;
            s.push_back(in);
        }
        S.push_back(s);
    }
    vector<int> P;
    rep (i, 0, M) {
        int p; cin >> p;
        P.push_back(p);
    }

    int ans = 0;
    rep (bit, 0, (1 << N)) {
        rep (i, 0, M) {
            int total_p = 0;
            rep (j, 0, S[i].size()) {
                if (bit & (1 << S[i][j])) ++total_p;
            }
            if (total_p % 2 != P[i]) break;
            if (i == M-1) ++ans;
        }
    }

    cout << ans << endl;
}

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

int main() {
	// your code goes here
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long n,W,i,j,k,V;
	cin>>n>>W;
	long long w[n],v[n];
	
	V=0;
	for(i=0;i<n;i++)
	{
		cin>>w[i]>>v[i];
		V+=v[i];
	}

	long long dp[V+1];
	dp[0]=0;
	for(i=1;i<=V;i++)
	dp[i]=1e18L;

	for(i=0;i<n;i++)
	{
		for(j=V-v[i];j>=0;j--)
		{
			dp[v[i]+j]=min(dp[v[i]+j],dp[j]+w[i]);
		}
	}

	k=(long long )1e18;
	for(i=0;i<=V;i++)
	{
		if(dp[i]<=W)
		k=i;
	}
	cout<<k;
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {

    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	// 入力
    	int n = sc.nextInt();
    	int x = sc.nextInt();
    	int min = 100000;
    	int cnt = 0;

    	for (int i = 0; i < n; i++){
    		int m = sc.nextInt();
    		x-= m;
    		min = Math.min(m, min);
    		cnt++;
    	}

    	while(x >= min) {
    		x-= min;
    		cnt++;
    	}

    	// 出力
    	System.out.println(cnt);
    }
}

Measured memory_bytes: 23124
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n;
    cin >> n;

    vll A(n);
    REP(i, n) cin >> A[i];

    ll ans = 0;
    ll prev = A[0];
    FOR(i, 1, n) {
        if (A[i] < prev) ans += prev - A[i];
        prev = max(prev, A[i]);
    }

    print(ans);
}


Measured memory_bytes: 4772
n, m = map(int, input().split())
ab = [ list(map(int, input().split())) for _ in range(n) ]
cd = [ list(map(int, input().split())) for _ in range(m) ]
for a, b in ab:
  ans = float("inf")
  for j in range(m):
    c, d = cd[j]
    temp = abs(a-c) + abs(b-d)
    if temp < ans:
      ans = temp
      cur = j+1
  print(cur)
    

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 101;
const int INF = 1<<28;

int main(){
  int n,cost[MAX][MAX],a,b,c;
  while(cin >> n, n){
    fill(cost[0],cost[MAX],INF);

    int M = 0;
    for(int i = 0 ; i < n ; i++){
      cin >> a >> b >> c;
      cost[a][b] = cost[b][a] = c;
      M = max(M,max(a,b));
    }
    ++M;
    for(int k = 0 ; k < M ; k++)
      for(int i = 0 ; i < M ; i++)
	for(int j = 0 ; j  < M ; j++)
	  cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);

    int ans = INF,sum,num;
    for(int i = 0 ; i < M ; i++){
      sum = 0;
      for(int j = 0 ; j < M ; j++){
	if(i == j) continue;
	sum += cost[i][j];
      }
      if(sum < ans){
	ans = sum;
	num = i;
      }
    }
    cout << num << ' ' << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1196
/*
AOJ - ITP1_8_d
Date: 20181006
Author: Mikoron * ♡mikoiwate♡
 */

#define MAX 100

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
        char w[MAX], sw[MAX];
        short i, j, w_c, sw_c, ring_j, flag;

        scanf("%s", w);
        w_c = (short)strlen(w);
        scanf("%s", sw);
        sw_c = (short)strlen(sw);

        for(i = 0; i < w_c; i++) {
                if(w[i] == sw[0]) {
                        flag = 1;
                        for(j = 0; j < sw_c; j++) {
                                if(i+j >= w_c) ring_j = (i+j) - w_c;
                                else ring_j = i+j;

                                if(sw[j] != w[ring_j]) {
                                        flag = 0;
                                        break;
                                }
                        }
                        if(flag == 1) break;
                }
        }

        if(flag == 1) printf("Yes\n");
        else printf("No\n");

        return 0;
}



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

public class Main{

  public static void main(String[] args) throws IOException {
    // 標準入力用
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    // 標準入力の値を、半角スペースで分割
    String[] inputRowAndCol = (input.readLine()).split("\\s");
    int row = Integer.parseInt(inputRowAndCol[0]); // 行
    int col = Integer.parseInt(inputRowAndCol[1]); // 列

    // 行列A
    int[][] matrixA = new int[row][col];
    String[] matrixData = null; // 実際の行列のデータ用
    // 行の数だけ繰り返し
    for (int i = 0; i < row; i++) {
      // 標準入力の値を、半角スペースで分割
      matrixData = (input.readLine()).split("\\s");
      // 列の数だけ繰り返し
      for (int j = 0; j < col; j++) {
        // 行列Aに、標準入力の値を設定していく
        matrixA[i][j] = Integer.parseInt(matrixData[j]);
      }
    }
    // ベクトルb
    int[] vectorB = new int[col];
    for (int k = 0; k < col; k++) {
      vectorB[k] = Integer.parseInt(input.readLine());
    }

    // 行列の積
    // 行の数だけ繰り返し
    for (int l = 0; l < row; l++) {
      int result = 0; // リセット（次の行の計算のため初期化）
      // 列の数だけ繰り返し
      for (int m = 0; m < col; m++) {
        // 計算
        result += (matrixA[l][m] * vectorB[m]);
      }
      // 表示
      System.out.println(result);
    }
  }
}


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

using namespace std;
#define ll long long
const int MAXN = 2e5 + 1;
vector<ll> arr(2e5+2, 0);
vector<ll> dp(2e5+2, 0);
vector<ll> left1(2e5+2, 0);
void solve() {
    int n;
    cin>>n;
    ll summ=0;
    vector<ll> prefsumm (n+1, 0);
    vector<ll> arr (n+1);
    for(int i=1;i<=n;i++) {
        cin>>arr[i];
        prefsumm[i]+=prefsumm[i-1]+arr[i];
        summ+=arr[i];
    }
    ll ans=1e14;
    for(int i=2;i<=n;i++){
        ll delta=abs(summ-2*prefsumm[i-1]);
        ans=min(delta, ans);
    }
    cout<<ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 8064
#include <iostream>

using namespace std;

int main(){

    int n;

    cin >> n;

    bool ret = false;

    for(int i = 1; i < 10; i++){
        if (n % i == 0 && n / i < 10)
            ret = true;
    }
    
    if(ret)
        cout << "Yes";
    else
        cout << "No";

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 5007, MOD = 1000 * 1000 * 1000 + 7;

int mod(int n) {
    n %= MOD;
    if (n < 0) return n + MOD;
    else return n;
}   
int fp(int a, int p) {
    int ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = mod(ans * c);
        c = mod(c * c);
    }   
    return ans;
}   
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }
void add(int &a, int b) { a = mod(a + b); }

int dp[N][N][2], t1[N][N][2], t2[N][N][2];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n, a, b;
    cin >> n >> a >> b;

    if (b < a)
        swap(a, b);

    for (int i = 1; i <= n; ++i) {
        for (int t = 0; t < 2; ++t) {
            int to = i;
            if (t == 0 && i < a)
                to = 0;
            dp[i][to][t] = 1;
        }   
    }   
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < b; ++j) {
            for (int t = 0; t < 2; ++t) {

                add(t1[i][j][t], t1[i - 1][j][t]);
                add(dp[i][j][t], t1[i][j][t]);
                if (i && j) {
                    add(t2[i][j][t], t2[i - 1][j - 1][t]);
                }
                add(dp[i][j][t], t2[i][j][t]);
                int x = dp[i][j][t];

                if (t) {
                    if (1 < a) {
                        add(t1[i + 1][0][t^1], x);
                        if (i + a <= n) {
                            add(t1[i + a][0][t^1], -x);
                        }
                    }
                    if (a < b - j) {
                        if (i + a <= n && j + a <= n) {
                            add(t2[i + a][j + a][t^1], x);
                        }
                        if (i + b - j <= n && j + b - j <= n) {
                            add(t2[i + b - j][j + b - j][t^1], -x);                            
                        }   
                    }   
                }   
                else {
                    if (1 < b - j) {
                        add(t2[i + 1][j + 1][t^1], x);
                        if (i + b - j <= n && j + b - j <= n) {
                            add(t2[i + b - j][j + b - j][t^1], -x);                            
                        }   
                    }
                    /*
                    for (int k = 1; k < b - j; ++k)
                        add(dp[i + k][j + k][t^1], x);                        
                    */
                }   
            }   
        }   
    }   

    int ans = 1;
    for (int i = 0; i < n; ++i) 
        ans = (ans << 1) % MOD;
    for (int i = 0; i < b; ++i)
        for (int t = 0; t < 2; ++t)
            ans = mod(ans - dp[n][i][t]);
    cout << ans << endl;            
}

Measured memory_bytes: 590460
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n,a[N * N],h,w,ans[N][N];
int main() {
  scanf("%d%d",&h,&w);
  scanf("%d",&n);
  for (int i = 1 ; i <= n ; ++ i)
    scanf("%d",&a[i]);
  int p = 1;
  for (int i = 1 ; i <= h ; ++ i) {
    if (i&1) {
      for (int j = 1 ; j <= w ; ++ j) {
	ans[i][j] = p;
	if (--a[p] == 0) p ++;
      }
    } else {
      for (int j = w ; j >= 1 ; -- j) {
	ans[i][j] = p;
	if (-- a[p] == 0) p ++;
      }
    }
  }
  for (int i = 1 ; i <= h ; ++ i) {
    for (int j = 1 ; j <= w ; ++ j)
      printf("%d ",ans[i][j]);
    printf("\n");
  }
  return 0;
}


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

using namespace std;

int main(){
    int N,t,x,y,bt=0,bx=0,by=0;
    bool ans = true;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> t >> x >> y;
        if(t-bt < abs(x-bx) + abs(y-by) || abs(abs(x-bx)+abs(y-by))%2 != (t-bt)%2){
            ans = false;
            break;
        }
        bt = t;
        bx = x;
        by = y;
    }

    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define num first
#define energy second
typedef pair<int,int> pii;

int H , W , S;
int mat[40][40];
pii dp[40][40][40][40];
int count(int x1,int y1,int x2,int y2){
	return mat[y2-1][x2-1] - mat[y2-1][x1-1] - mat[y1-1][x2-1] + mat[y1-1][x1-1];
}

pii dfs(int x1 , int y1 , int x2 , int y2){
	if(~dp[x1][y1][x2][y2].num) return dp[x1][y1][x2][y2];
	if(mat[H][W] - count(x1,y1,x2,y2) > S) return mp(-10000,1);
	pii ans = mp(1,S-(mat[H][W] - count(x1,y1,x2,y2)));
	
	for(int i = x1+1 ; i < x2 ; i++){
		pii A = dfs(x1,y1,i,y2);
		pii B = dfs(i,y1,x2,y2);
		pii get = mp(A.num + B.num , min(A.energy,B.energy) );
		ans = max( ans , get);
	}
	for(int i = y1+1 ; i < y2 ; i++){
		pii A = dfs(x1,y1,x2,i);
		pii B = dfs(x1,i,x2,y2);
		pii get = mp(A.num + B.num , min(A.energy,B.energy) );
		ans = max( ans , get);
	}
	
	return dp[x1][y1][x2][y2] = ans ;
}

int main(){
	int t;
	while(cin >> H >> W >> S , H){
		memset(mat,0,sizeof(mat));
		for(int i = 0 ; i < 40 ; i++)
			for(int j = 0 ; j < 40 ; j++)
				for(int k = 0 ; k < 40 ; k++)
					for(int l = 0 ; l < 40 ; l++)
						dp[i][j][k][l] = mp(-1,-1);
		for(int i = 1 ; i <= H ; i++)
			for(int j = 1 ; j <= W ; j++)
				cin >> t , mat[i][j] = t + mat[i][j-1];
		for(int i = 1 ; i <= H ; i++)
			for(int j = 1 ; j <= W ; j++)
				mat[i][j] += mat[i-1][j];
		pii result = dfs(1,1,W+1,H+1);
		cout << result.num << " " << result.energy << endl;
	}
}

Measured memory_bytes: 20000
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define double long double
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool integer(double n){
	if(n==long(n))return true;
	else return false;	
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
} 
bool search(int x){
	int n;
	int a[n];
	int l=0,r=n;
	while(r-l>=1){
		int i=(l+r)/2;
		if(a[i]==x)return true;
		else if(a[i]<x)l=i+1;
		else r=i;
	}
	return false;
}
int h,w;
char c[55][55];
void dfs(int x,int y){
	c[x][y]='0';
	for(int i=-1;i<=1;i++)for(int j=-1;j<=1;j++){
		int nx=x+i;
		int ny=y+j;
		if(0<=nx&&nx<w&&0<=ny&&ny<h&&c[nx][ny]=='1')dfs(nx,ny);
	}
	return ;
}	
signed main(){
	bool a=true;
	while(a){
		int ans=0;
		cin>>h>>w;
		if(h==0&&w==0)return 0;
		rep(0,i,w)rep(0,j,h)cin>>c[i][j];
		rep(0,i,w)rep(0,j,h){
			if(c[i][j]=='1'){
				dfs(i,j);
				ans++;
			}
		}
		c(ans)
	}	
}	


Measured memory_bytes: 3152
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const long long INFL = 2e18;
const int MOD = 1000000007;
int main(){
	int H,W,N;
	cin >> H >> W >> N;
	vector<int> a(N);
	vector<int> b(N);
	for(int i = 0;i < N;i++)cin >> a[i] >> b[i];

	map<pair<int,int>,int> mp;
	for(int i = 0;i < N;i++){
		for(int j = -1;j <= 1;j++){
			for(int k = -1;k <= 1;k++){
				if(2 <= a[i] + j && a[i] + j <= H - 1 && 2 <= b[i] + k && b[i] + k <= W - 1){
					mp[make_pair(a[i]+j,b[i]+k)]++;
				}
			}
		}
	}
	vector<ll> cnt(10);
	ll sum = 0;
	for(auto p:mp){
		cnt[p.second]++;
		sum++;
	}


	cnt[0] = (ll)(H-2) * (W-2) - sum;

	for(ll ans:cnt)cout << ans << endl; 
}


Measured memory_bytes: 60192
import java.util.*

fun selectionSort(A: Array<Int>) {
    var count = 0
    for (i in A.indices) {
        var minj = i
        for (j in i until A.size) {
            if (A[j] < A[minj]) {
                minj = j
            }
        }
        if (A[i] != A[minj]) {
            count++
        }
        A[i] = A[minj].also { A[minj] = A[i] }
    }
    println(A.joinToString(" "))
    println(count)
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val N = scanner.nextInt()
    val list = mutableListOf<Int>()
    for (i in 0 until N) {
        list.add(scanner.nextInt())
    }
    selectionSort(list.toTypedArray())
}


Measured memory_bytes: 30064
def myAnswer(N:int,S:list) -> int:
   rightW = S.count("W")
   rightE = N - rightW
   leftW = 0
   leftE = 0
   ans = 10**10
   for s in S:
      if(s == "W"):
         rightW -= 1
         ans = min(ans,rightE + leftW)
         leftW += 1
      else:
         rightE -= 1
         ans = min(ans,rightE + leftW)
         leftE += 1
   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   S = list(input())
   print(myAnswer(N,S))
if __name__ == '__main__':
   main()

Measured memory_bytes: 6048
N=list(input())
import sys
mark=0
for i in range (len(N)):
    if N[i]!='9':
        mark=i
        break
if mark==0 and N[mark+1:]==['9']*len(N[mark+1:]):
    count=0
    for l in range (len(N)):
        count+=int(N[l])
    print(count)
    sys.exit()
N[0]=str(int(N[0])-1)
for j in range (1,len(N)):
    N[j]='9'
count=0
for k in range (len(N)):
    count+=int(N[k])
print(count)

Measured memory_bytes: 3064
# 折れ線グラフで考えると
# ( : +1
# ) : -1
# 0で終わる
# 0未満にならない → 各文字列で最下点と和を利用
# 和がマイナスの部分と分けて、マイナス部分は反転して考える

import sys
input = sys.stdin.readline

n = int(input())
s = [input().strip() for _ in range(n)]
plus = []
minus = []
for i in s:
    min_v = 0
    sum_v = 0
    for j in i:
        sum_v += 1 if j == '(' else -1
        min_v = min(min_v, sum_v)
    if sum_v > 0:
        plus.append((min_v, sum_v))
    else:
        minus.append((min_v-sum_v, -sum_v))

plus.sort(key=lambda x:x[0], reverse=True)
minus.sort(key=lambda x:x[0], reverse=True)

sum_plus = 0
for min_v, sum_v in plus:
    if sum_plus + min_v < 0:
        print("No")
        exit()
    sum_plus += sum_v

sum_minus = 0
for min_v, sum_v in minus:
    if sum_minus + min_v < 0:
        print("No")
        exit()
    sum_minus += sum_v

if sum_plus == sum_minus:
    print("Yes")
else:
    print("No")





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

int main(){
  int n, i, flag = 0;
  cin >> n;
  for(i = 0; i*7 <= n; i++) if(!((n-7*i)%4)) flag = 1;
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	a := readi()
	if a <= 999 {
		fmt.Println("ABC")
		return
	}
	fmt.Println("ABD")
}

// IO---------------------------------------------------

func readi() (n int) {
	fmt.Scan(&n)
	return
}

func readf() (n float64) {
	fmt.Scan(&n)
	return
}

func reads() (n string) {
	fmt.Scan(&n)
	return
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func scanSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func scanFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func yesorno(b bool) {
	if b {
		fmt.Println("yes")
		return
	}
	fmt.Println("no")
}

// calc---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, v, j;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a.at(i);
	}
	for (int i = 1; i < n; ++i) {
		for (int k = 0; k < n; ++k) {
			cout << a.at(k);
			if (k == n - 1) {
				cout << endl;
			} else {
				cout << " ";
			}
		}
		v = a.at(i);
		j = i - 1;
		while (j >= 0 && a.at(j) > v) {
			a.at(j + 1) = a.at(j);
			j--;
		}
		a.at(j + 1) = v;
	}
	for (int i = 0; i < n; ++i) {
		cout << a.at(i);
		if (i == n - 1) {
			cout << endl;
		} else {
			cout << " ";
		}
	}
}


Measured memory_bytes: 3088
#include <stdio.h>
int main(void)
{
    int n, i;
    double x[10], ans=0;
    char u[10][4];

    scanf("%d", &n);

    for(i=0;i<n;i++){
        scanf("%lf %s", &x[i], u[i]);
    }

    for(i=0;i<n;i++){
        if(u[i][0]=='J') ans=ans+x[i];
        else ans=ans+x[i]*380000.0;
    }

    printf("%f\n", ans);
        
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    char c;
    cin>>c;
    cout<<char(c+1);
}
int main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)foo();
}

Measured memory_bytes: 256
#include <cstdio>

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

    int min = a[0],max = a[0];
    for(int i = 1; i < n; i++){
        if(min > a[i]){
            min = a[i];
        }
        if(a[i] > max){
            max = a[i];
        }
    }
    printf("%d\n", max - min);

    return 0;
}

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

int main() {
 
  int fif = 0;
  int sev = 0;
  
  for(int i = 0; i < 3; i++){
    int a;
    cin >> a;
    if(a == 5){
      fif++;
    }
    else if(a == 7){
      sev++;
    }
  }
  
  if(sev == 1 && fif == 2){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

// DAME:
/*

*/
struct Node{
    int to;
    ll cost;
};

int n, m;
ll d[100001];
bool used[100001];

void dijkstra(vector<vector<Node>> G){
    // (cost, point)
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    fill(d, d+n, INF);
    fill(used, used+n, false);
    d[0] = 0;
    que.push(make_pair(0, 0));
    while(!que.empty()){
        pair<int, int> f = que.top(); que.pop();
        int cur = f.second;
        if(used[cur]) continue;
        // 最小値ではないため、見送り
        if(d[cur] < f.first) continue;
        used[cur] = true;
        rep(i, G[cur].size()){
            int next = G[cur][i].to;
            ll cost = G[cur][i].cost;
            if(d[next] > d[cur] + cost){
                d[next] = d[cur] + cost;
                que.push(make_pair(d[next], next));
            }
        }
    }
}

int main() {
    cin >> n >> m;
    vector<vector<Node>> G(n);
    // lからrにコストcの辺を追加
    rep(i, m){
        int l, r;
        ll c;
        cin >> l >> r >> c;
        l--, r--;
        G[l].emplace_back(Node{r, c});
    }
    // 逆向きの有効辺を追加
    rep(i, n-1) G[i+1].emplace_back(Node{i, 0});

    dijkstra(G);
    ll ans = (d[n-1]==INF) ? -1 : d[n-1];
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

bool c(char c){
  if(c=='T')return true;
  else return false;
}

bool f(bool x,bool y){
  if(x&&!y)return false;
  else return true;
}

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

  int n;
  cin>>n;
  bool x;
  {
    char a;
    cin>>a;
    x=c(a);
  }
  rep(i,n-1){
    char a;
    cin>>a;
    bool y=c(a);
    x=f(x,y);
  }
  if(x)cout<<"T"<<endl;
  else cout<<"F"<<endl;

  return 0;
}



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

ll solve(ll n, ll m){
    if(n > m) return solve(m, n);
    if(n == 1LL && m == 1LL) return 1LL;
    if(n == 1LL) return m-2LL;
    return (n-2LL)*(m-2LL);
}

int main() {
    ll n, m;
    cin >> n >> m;
    cout << solve(n,m) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll K;
    cin >>K;
    ll ans = 0;
    vector<vector<ll>> gc(K+1,vector<ll>(K+1));
    rep2(j,K){
            rep2(k,K){
                 gc[j][k]= gcd(j,k);
            }
    }
    
    rep2(i,K){
        rep2(j,K){
            rep2(k,K){
                ans += gcd(i,gc[j][k]);
            }
        }
    }
    
    cout << ans << endl;


    return 0;
    

}

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

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

    if(d == 0 && n != 100) cout << n;
    else if(d == 1 && n != 100) cout << n*100;
    else if(d == 2 && n != 100) cout << n*10000;
    else if(d == 0 && n == 100) cout << 101;
    else if(d == 1 && n == 100) cout << 10100;
    else if(d == 2 && n == 100) cout << 1010000;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
A = list(map(int,input().split()))

def is_ok(s):
    cnt = 0
    for i in range(n):
        cnt += (A[i]-1)//s
    return cnt<=k
def main():
    left = 0
    right = max(A)
    while (right-left)>1:
        mid = (right+left)//2
        if is_ok(mid):
            right = mid
        else:
            left = mid
    return right
print(main())


Measured memory_bytes: 30812
#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++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(b-a == c-b) cout<<"YES"<<endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  bool ok = true;
  rep(i,n){
    if((i+1)%2==0 && s[i]=='R') ok = false;
    if((i+1)%2==1 && s[i]=='L') ok = false;
  }
  if(ok) puts("Yes"); else puts("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
ll n;
vb done;
ll add=0,c=1;
vi ans;
void solve(int a,int b){
    if(a==b)return;
    ans.pb(a);
    int t=0;
    while(((a>>t&1)^(b>>t&1))==0)t++;
    vi num(n-c);
    int k=0;
    rep(i,n){
        if(done[i]||i==t)continue;
        num[k]=i;
        k++;
    }
    rep(i,(1<<(n-c))-1){
        int s=0;
        while(!((i+1)>>s&1))s++;
        a^=1<<num[s];
        ans.pb(a);
    }
    c++;
    done[t]=true;
    solve(a^(1<<t),b);
}
int main(){
    ll a,b;cin>>n>>a>>b;
    done=vb(n,false);
    int cnt=0;
    rep(i,n)if((a>>i&1)^(b>>i&1))cnt++;
    if(cnt%2==0)dame("NO");
    out("YES");
    solve(a,b);
    ans.pb(b);
    outv(ans);
}

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

int main(){
  int n;
  cin >> n;
  int counter;
  int biggest = -1;
  int num;
  for (int i=1; i<=n; i++){
    int x = i;
    counter = 0;
    while (true){
      if (x%2 == 0 && x != 0){
        x = x/2;
        counter++;
      }else{
        break;
      }
    }
    if (counter > biggest){
      biggest = counter;
      num = i;
    }
  }
  cout << num;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

	

int32_t main()
{
	int n;cin>>n;
	if( n <=  1e7 )
	{
		int ans = 0;
		for(int i=2;i<=n;i++)
		{
			int x = n ;
			while( x % i == 0 ) x/=i;
			if( x == 1 || x %i == 1 ) ans++;
		}
		cout << ans << endl; return 0;
	}
	set<int>st;
	st.insert(2);
	for(int i=2;i*i<=n;i++)
	{
		int x = n ;
		while( x %i == 0 )x/=i;
		if( x == 1 || x%i == 1 ) st.insert(i);
		
	}
	st.insert(n);
	for(int i=2;i*i<=n;i++)
	{
		if( (n-1)%i == 0 ) 
		{
			st.insert(i);
			st.insert((n-1)/i);
		}
	}
	if( n-1 >=1)st.insert(n-1);
	cout << st.size() << endl;
	

}


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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a, b;
  cin >> a >> b;
  if (a > b) {
    swap(a, b);
  }
  if (a == 0 || b == 0) {
    cout << "Zero" << endl;
  } else if (a > 0 && b > 0) {
    cout << "Positive" << endl;
  } else if (a > 0 || b > 0) {
    cout << "Zero" << endl;
  } else {
    cout << (abs(a - b) % 2 ? "Positive" : "Negative") << endl;
  }
  return 0;
}



Measured memory_bytes: 256