akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int a[4][4]={};
    int n;
    int b;
    int c[99]={};
    int tmp=0;
    int k=0;
    
    cin >> a[1][1] >> a[1][2] >> a[1][3];
    cin >> a[2][1] >> a[2][2] >> a[2][3];
    cin >> a[3][1] >> a[3][2] >> a[3][3];
    cin >> n;
    
    for(int i=1; i<=n; i++){
        
        cin >> b;
        
        if(b==a[1][1]){
            
            c[11] = 1;
            
        } else if(b==a[1][2]){
            
            c[12] = 1;
            
        } else if(b==a[1][3]){
            
            c[13] = 1;
            
        } else if(b==a[2][1]){
            
            c[21] = 1;
            
        } else if(b==a[2][2]){
            
            c[22] = 1;
            
        } else if(b==a[2][3]){
            
            c[23] = 1;
            
        } else if(b==a[3][1]){
            
            c[31] = 1;
            
        } else if(b==a[3][2]){
            
            c[32] = 1;
            
        } else if(b==a[3][3]){
            
            c[33] = 1;
            
        }
        
    }
    
    for(int i=1; i<=3; i++){
        
        k = 0;
        
        for(int j=1; j<=3; j++){
            
            tmp = i * 10 + j;
            k += c[tmp];
            
            if(k>=3){
                
                cout << "Yes" << endl;
                return 0;
                
            }
            
        }
        
    }
    
    for(int i=1; i<=3; i++){
        
        k = 0;
        
        for(int j=1; j<=3; j++){
            
            tmp = j * 10 + i;
            k += c[tmp];
            
            if(k>=3){
                
                cout << "Yes" << endl;
                return 0;
                
            }
            
        }
        
    }
    
    k = 0;
    
    for(int i=1; i<=3; i++){
        
        tmp = i * 11;
        k += c[tmp];
        
        if(k>=3){
            
            cout << "Yes" << endl;
            return 0;
            
        }
        
    }
    
    k = 0;
    
    for(int i=1; i<=3; i++){
        
        tmp = i * 9 + 4;
        k += c[tmp];
        
        if(k>=3){
            
            cout << "Yes" << endl;
            return 0;
            
        }
        
    }
    
    cout << "No" << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
N,M = map(int,input().split())
es = [[] for i in range(N)]
for i in range(M):
    a,b = map(lambda x:int(x)-1,input().split())
    es[a].append(b)
    es[b].append(a)

start = 0
visited = [0] * N
ans = [[],[]]
for i in range(2):
    stack = [start]
    visited[start] = 0
    while stack:
        v = stack.pop()
        visited[v] = 1
        ans[i].append(v)
        finish = 1
        for to in es[v]:
            if visited[to]: continue
            stack.append(to)
            finish = 0
        if finish:
            break

ans = ans[0][::-1] + ans[1][1:]
print(len(ans))
print(' '.join(list(map(lambda x:str(x+1), ans))))

Measured memory_bytes: 29072
import java.util.*;
public class Main{

     public static void main(String []args){
        
        
        
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        scanner.nextLine();
        String[] splt = scanner.nextLine().split(" ");
        List<String> list = new ArrayList<>();
        for(String sp: splt){
            list.add(sp);
        }
        Collections.sort(list);
        String answer = "YES";
        for(int x = 0; x<N-1; x++){
            if(list.get(x).equals(list.get(x+1))){
                answer = "NO";
                break;
            }
        }
        System.out.println(answer);
        
        
        
     }
}

Measured memory_bytes: 63168
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;
const int MOD = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> key;
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        int s = 0;
        for (int j = 0; j < b; j++) {
            int c; cin >> c;
            c--;
            s |= 1<<c;
        }
        key.emplace_back(pair<int, int>(s, a));
    }

    vector<int> dp(1<<n, INF);
    dp[0] = 0;
    for (int before = 0; before < 1<<n; before++) {
        for (int i = 0; i < m; i++) {
            int after = before | key[i].first;
            dp[after] = min(dp[after], dp[before]+key[i].second);
        }
    }
    int ans = dp[(1<<n)-1];
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	char train[2048];
	int n;
	cin>>n;
	while(n--){
		int x=0;
		string s,ans;
		cin>>s;
		ans+=s[0];
		for(int i=0;i<(s.length()-1)/3;i++){
			int k=i*3+1;
			if(s[k]=='<'){
				if(x==0){
					string tmp=s[k+2]+ans;
					ans=tmp;
				}else x--;
			}else if(s[k+1]=='>'){
				if(ans[x+1]!=s[k+2]){
					ans+=s[k+2];
					x++;
				}else x++;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1212
// Wed Jul 29 19:48:22 IST 2020    
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)        for(int ii = (int)a ; ii < (int)b  ; ii++ )
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long   
#define all(x)             (x).begin(),(x).end() 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
using namespace std ;    
// policy based   
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
 
const int MOD = 1e9+7;
const double pi = 3.141592653589793238;
const int N = 2e5+7; 
const int INF = INT_MAX;
 
int tests(){
    int n,k;
    cin >> n >> k;
    vector <int> v(n);
    for(int& t :v)
        cin >> t;
    sort(v.rbegin(),v.rend());
    auto possible = [&](int number){
        int steps = 0;
        for(int i = 0 ; i < n and v[i] > number ; i++){
            steps += (v[i])/number;
        } 
        return steps <= k;
    };
    int low = 1,ans = -1, high = 1e9,mid;
    while(low <= high){
        mid = low + (high-low)/2;
        if(possible(mid)){
            ans= mid;
            high = mid-1;
        }
        else{
            low = mid+1;
        }
    }
    cout << ans << '\n';
    return 0;
}   
int32_t main(){
    I__O ;     
    int cases = 1 ;  
    // cin >> cases ;
    for(int test = 1 ; test <= cases ; ++test){ 
        // cout << "Case #" << test << ":" << '\n';
        tests();
    }    
    return 0 ; 
}


Measured memory_bytes: 3976
#include<iostream>
#include<queue>
#include<bitset>
#include<algorithm>
#include<climits>
#include<vector>
#include<deque>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define dump(a) rep(i,a.size()){ cout<<a[i]<<" "; } cout<<endl;
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define INF INT_MAX/3
#define EPS 1e-7

int main(){
  ll n,a,b;
  ll x[100001];
  cin>>n>>a>>b;
  rep(i,n){
    cin>>x[i];
  }
  ll ans=0; //総移動距離
  rep(i,n-1){
    /* dbg(x[i+1]-x[i]); */
    /* dbg(ans); */
    ans += mmin((x[i+1]-x[i])*a, b);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int[] order = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1};
		
		for (int i = 0; i < order.length; i++) {
			if (a == order[i]) { a = i; break; }
		}
		
		for (int i = 0; i < order.length; i++) {
			if (b == order[i]) { b = i; break;}
		}
		if (a == b) {
			System.out.println("Draw");
		} else if (a > b) {
			System.out.println("Alice");
		} else {
			System.out.println("Bob");
		}
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 23124
def pow_mod(x, y, mod=10**9 + 7):
    if y == 0:
        return 1
    res = 1
    for i in range(y.bit_length()):
        if y & (1 << i):
            res *= x
            res %= mod
        x *= x
        x %= mod
    return res


n, x, m = map(int, input().split())

order = [0] * (m+1)
cnt = [-1] * (m+1)

now = x
a = -1
b = -1
for i in range(n):
    if cnt[now] != -1:
        a = cnt[now]
        b = i
        break
    order[i] = now
    cnt[now] = i
    now = pow_mod(now, 2, m)

if a == -1 and b == -1:
    print(sum(order))
    exit()

ans = 0
roop = [0]
for i in range(b):
    if i < a:
        ans += order[i]
    else:
        roop.append(order[i] + roop[-1])

n -= a

tmp = n % (b-a)
freq = n // (b-a)

ans += roop[-1] * freq
ans += roop[tmp]
print(ans)



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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a, b, h;
    cin >> a >> b >> h;

    cout << (a+b)*h/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#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++)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);


int main() {
	int n;
	cin >> n;
	string s;
	map<string, int> ss;
	rep(i, n) {
		cin >> s;
		ss[s]++;
	}

	printf("AC x %d\n", ss["AC"]);
	printf("WA x %d\n", ss["WA"]);
	printf("TLE x %d\n", ss["TLE"]);
	printf("RE x %d\n", ss["RE"]);

	return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int a, b;
	cin>>a>>b;
	if(a == 0 || b==0)cout<<"Zero"<<endl;
	else if(a > 0) cout<<"Positive"<<endl;
	else if(a < 0 && b > 0) cout<<"Zero"<<endl;
	else if((b-a) %2 == 0) cout<<"Negative"<<endl;
	else cout<<"Positive"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//using
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);

//テンプレート関数
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl kai(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,桁数回の演算だからだいたいO(logN)くらい?



signed main(){
    cout << fixed << setprecision(10);
    int d;
    cin >> d;
    int c[26];
    rep(i,26)cin >> c[i];
    int s[d][26];
    rep(i,d){
        rep(j,26)cin >> s[i][j];
    }
    int t[d];
    rep(i,d){
        cin >> t[i];
        t[i]--;
    }
    int last_day[26];
    m0(last_day);
    intl ans = 0;
    rep(i,d){
        ans += s[i][t[i]];
        last_day[t[i]] = i + 1;
        //debug(ans);
        rep(j,26){
            ans -= (c[j] * ((i + 1) - last_day[j])); 
        }
        cout << ans << endl;
    }
    //cout << "ok" << endl;
    return 0;
}


Measured memory_bytes: 3672
X, N = map(int, input().split())
P = list(map(int, input().split()))
Pli = set(sorted(P))
X1 = X
X2 = X
while True:
    if X1 not in Pli:
        print(X1)
        break
    elif X2 not in Pli:
        print(X2)
        break
    else:
        X1 -= 1
        X2 += 1

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

int main(){
int N;
cin >> N;
int A[10][10] ={0};
for(int i = 1; i <= N; i++){
  string S = to_string(i);
  int len = S.length();
  A[S[0] - '0'][S[(len - 1)] - '0']++;
}
int ans = 0;
for(int i = 1; i < 10; i++)for(int j = 1; j < 10; j++){
  ans += A[i][j] * A[j][i];
}

print(ans);

}

Measured memory_bytes: 256
#include <cstdio>
const int MAXN = 55;
char S[MAXN];
int N;

int main() {
  scanf(" %d%s", &N, S);
  int ret = 0;
  for (int i = 2; i < N; ++i) {
    if ((S[i] == 'C') && (S[i-1] == 'B') && (S[i-2] == 'A')) {
      ++ret;
    }
  }
  printf("%d\n", ret);
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	map<string, int> mp;
	ll ans = 0;
	for(int i = 0; i < n; i++){
		string s; cin>>s;
		sort(s.begin(), s.end());
		ans += mp[s];
		mp[s]++;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 11264
row, col = map(int, raw_input().split())

ret = []
for _ in range(row):
    _row = map(int, raw_input().split())
    _row += [sum(_row)]
    ret.append(_row)

for i in ret:
    print ' '.join(map(str, i))

ret_sum = []
for i in range(col+1):
    work = 0
    for j in ret:
        work += j[i]
    ret_sum.append(work)

print ' '.join(map(str, ret_sum))


Measured memory_bytes: 4688
using System;
class Program
{
	static void Main()
	{
	string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
	int n = int.Parse(input[0]);
	int k = int.Parse(input[1]);
    long answer = k;
    for(int i = 2; i <= n; i++)answer *= k - 1;

	Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}

Measured memory_bytes: 11092
import sys
from collections import deque
input = sys.stdin.readline

N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10**9

def dfs(cur, a, b, c):
    if cur == N:
        if min(a, b, c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return INF #長さ0になった場合
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3316
from bisect import bisect_left, bisect_right

n,m = map(int, input().split())
al = list(map(int, input().split()))
al.sort()

ok, ng = 0, 10**18+1
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    ok_flag = True
    cnt = 0
    # print('-----')
    # print(ok,ng,mid)
    for i,a in enumerate(al):
        rem = mid-a
        cnt_a = n-bisect_left(al,rem)
        # cnt_a = min(n-i-1, cnt_a)
        cnt += cnt_a
        # print(i,a,cnt_a)
    if cnt >= m:
        ok = mid
    else:
    	ng = mid

min_sum = ok
cum_sums = [0]
csum = 0
for a in al:
    csum += a
    cum_sums.append(csum)
    
# print(min_sum)

ans = 0
cnt = 0
for i,a in enumerate(al):
    rem = min_sum - a
    ind = bisect_left(al, rem)
    # ind = ind if 0 <= ind < n else None
    # ind = max(i+1,ind)
    csum = cum_sums[n] - cum_sums[ind]
    # print(i,a,csum)
    ans += csum
    ans += a*(n-ind)
    cnt += (n-ind)

ans -= (cnt-m)*min_sum

print(ans)
# print(min_sum)

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

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	int sum = 0;
	for (int i = 1; i <= N; i++) {
		string s = to_string(i);
		int n = s.size();
		int sm = 0;
		for (int j = 0; j < n; j++) {
			sm += s[j] - '0';
		}
		if (A <= sm && sm <= B) {
			sum += i;
		}
	}
	cout << sum << endl;
}

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


int64_t ans=0;
string s;

void brute(int64_t sum, int64_t num, int k=0){
    if(k == s.length()){
        ans += num+sum;
        return;
    }
    brute(sum*10+s[k]-'0', num, k+1);
    if(sum) brute(s[k]-'0', num+sum, k+1);
}
int main(){
    cin >> s;
    brute(0,0,0);
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, h, w;

int main() {
    cin >> h >> w >> n;
    Vi a(n);
    REP(i, n) cin >> a[i];

    int x = 0, y = 0;
    REP(i, h) {
        V<string> s(w);
        REP(j, w) {
            s[j] = to_string(x+1);
            y++;
            if (y == a[x]) {
                x++;
                y = 0;
            }
        }
        if (i % 2 == 0) {
            REP(j, w) {
                cout << s[j];
                if (j != w-1) {
                    cout << ' ';
                }
            }
        } else {
            RREP(j, w-1, 0) {
                cout << s[j];
                if (j != 0) {
                    cout << ' ';
                }
            }
        }
        cout << '\n';
    }

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <inttypes.h>

int main(void)
{
    uint_fast16_t r, g, b;
    scanf("%" SCNuFAST16 " %" SCNuFAST16 " %" SCNuFAST16, &r, &g, &b);
    puts((r * 100 + g * 10 + b) % 4 == 0 ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;

int main(){
        int nums[5]={1,9,7,4},n;
        bool flags[5];
        for(int i=0;i<4;i++){
                cin >> n;
                for(int j=0;j<4;j++){
                        if(n==nums[j])  flags[j]=true;
                }
        }
        for(int i=0;i<4;i++){
                if(flags[i]!=true){
                        cout << "NO";
                        return 0;
                }
        }
        cout << "YES";
        return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	long long X,K,D; cin >> X >> K >> D;

	X = abs(X);
	long long ans = 0;
	if (X / D >= K) {
		ans = X - (K * D);
	}else {
		long long temae_made = (X / D);
		K -= temae_made;
		ans = X - (temae_made * D);		
		if (K % 2 == 1) {
			ans = abs(D - ans);
		}
	}
	cout << ans << endl;

		

	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pii pair<long long,long long>
#define pll pair<long long, long long>
#define rep(i,l,r) for(long long i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using namespace __gnu_pbds;

typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> order_set;

const long long INF = (long long)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

mt19937 mt('O' + '4' + 'K' + 'O');

void kekek()
{
    
    mt();
    #ifdef EB_UG
        freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
    #endif
    #ifndef EB_UG
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #endif
}

struct key {
    int pr, b;
    unsigned int msk = 0;
    key(int tp , int tb) {
        pr = tp;
        b = tb;
        for (int i = 0; i < tb; i++) {
            int t;
            cin >> t;
            msk |= (1U << (t - 1));
        }
    } 
};

int dp[1 << 12];

int main() {
    kekek();
    int n, m;
    cin >> n >> m;
    vector<key> keys;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        keys.push_back(key(a, b));
    }
    // for (int i = 0 ; i < m; i++) {
    //     cout << keys[i].pr << ' ' << keys[i].b << ' ' << keys[i].msk << endl;
    // }
    for (int i = 0; i < (1 << 12); i++) {
        dp[i] = INF;
    }
    dp[0] = 0;
    for (int msk = 0; msk < (1U << n); msk++) {
         for (int i = 0; i < m; i++) {
            dp[msk | keys[i].msk] = min(dp[msk | keys[i].msk], dp[msk] + keys[i].pr);
         }
    }
    int ans = dp[(1 << n) - 1];
    if (ans == INF) {
        cout << -1 << endl;
    }
    else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 380
#include <stdio.h>

#define INF 10000000

int main( void ) {
	int i, j, n, m, num[ 2 ][ 100 ], sum[ 2 ], min[ 2 ], diff;

	for ( ; scanf( "%d %d", &n, &m ), n; printf( min[ 0 ] == INF ? "-1\n" : "%d %d\n", min[ 0 ], min[ 1 ] ) ) {
		sum[ 0 ] = sum[ 1 ] = 0;
		for ( i = 0; i < n; i++ ) {
			scanf( "%d", num[ 0 ] + i );
			sum[ 0 ] += num[ 0 ][ i ];
		}
		for ( i = 0; i < m; i++ ) {
			scanf( "%d", num[ 1 ] + i );
			sum[ 1 ] += num[ 1 ][ i ];
		}

		diff = sum[ 0 ] - sum[ 1 ];
		min[ 0 ] = min[ 1 ] = INF;
		for ( i = 0; i < n; i++ )
			for ( j = 0; j < m; j++ )
				if ( ( num[ 0 ][ i ] - num[ 1 ][ j ] ) * 2 == diff )
					if ( num[ 0 ][ i ] + num[ 1 ][ j ] < min[ 0 ] + min[ 1 ] ) {
						min[ 0 ] = num[ 0 ][ i ];
						min[ 1 ] = num[ 1 ][ j ];
					}
	}

	return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define mod 1000000007
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
int a[maxn];
int n,l;
int main()
{
	n=read(); l=read();
	int sum=0,mn=0x3f3f3f3f;
	for(int i=1;i<=n;i++){
		sum+=l+i-1;
		if(std::abs(mn)>std::abs(l+i-1))mn=l+i-1;
	}
	writeln(sum-mn);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,r;
	cin >> n >> r;
	cout << (n >= 10 ? r : r + 100 * (10 - n));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll> PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

ll r,d,x;
Vi v;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>r>>d>>x;
    rep(i,10){
        x = r*x -d;
        print(x);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
/* 配列の初期化 fill(array, 0); すべて0に初期化 */
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );}
using namespace std;
int main()
{
    long long n,a,b;
    cin >> n >> a >> b;

    long long waru = n / (a + b);
    long long amari = n % (a + b);

    if(amari > a){
        amari = amari - (amari - a);
    }

    long long ans = waru * a + amari;

    cout << ans << endl;

    return 0;
}

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

int main() {
    while (1)
    {
        int n=0;
        cin >> n;
        if(n==0) break;
        vector<double>S(n);
        for(double &x : S){
            cin >> x;
        }
        double m = (double)accumulate(S.begin(), S.end(), 0) / n;
        double sum=0;
        for(double x : S){
            sum+=(x-m)*(x-m);
        }
        printf("%.8lf\n", sqrt(sum/n));
    }
    
    
    
	
    return 0;
}




Measured memory_bytes: 3208
n, m = map(int,input().split())
table = [[0 for j in range(n)] for i in range(n)]
v = []
for i in range(m):
    a, b = map(int,input().split())
    table[a-1][b-1] = 1
    table[b-1][a-1] = 1
    v.append((a-1,b-1))

def check(p):
    used[p] = 1
    for i in range(n):
        if p != i and table[p][i] == 1 and used[i] != 1:
            check(i)

ans = 0
for i in range(m):
    table[v[i][0]][v[i][1]] = 0
    table[v[i][1]][v[i][0]] = 0
    used = [0 for i in range(n)]
    check(0)
    if(sum(used) != n): ans += 1
    table[v[i][0]][v[i][1]] = 1
    table[v[i][1]][v[i][0]] = 1

print(ans)

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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 1e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

int a[N], b[N];

signed main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);
   int n, ans = 0, kol = 0;
   cin >> n;
   for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
   }
   for (int i = n - 1; i >= 0; i--) {
      a[i]+= kol;
      if (a[i] % b[i] != 0) {
         int ost = b[i] - (a[i] % b[i]);
         kol+= ost;
         ans+= ost;
      }
   }
   cout << ans;

}

Measured memory_bytes: 5120
nk=gets.chomp.split(" ").map(&:to_i)
h=gets.chomp.split(" ").map(&:to_i)
dp=Array.new(nk[0])
dp[0]=0
dp[1]=(h[0]-h[1]).abs
for i in 2..nk[0]-1
	min=dp[i-1]+(h[i]-h[i-1]).abs
	for j in 2..nk[1]
		break if(i-j<0)
		result=dp[i-j]+(h[i]-h[i-j]).abs
		min=result if(result<min)
	end
	dp[i]=min
end
p dp[nk[0]-1]

Measured memory_bytes: 12044
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;

int used[100100];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<pair<int,int> > a(n),b(n);
	for(int i=0;i<n;i++){
		cin >> a[i].first;
		a[i].second=i;
	}
	for(int i=0;i<n;i++){
		cin >> b[i].first;
		b[i].second=i;
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	for(int i=0;i<n;i++){
		if(a[i].first>b[i].first){
			cout << "No" << endl;
			return 0;
		}
	}
	for(int i=0;i<n-1;i++){
		if(a[i+1].first<=b[i].first){
			cout << "Yes" << endl;
			return 0;
		}
	}
	int p[n];
	for(int i=0;i<n;i++){
		p[a[i].second]=b[i].second;
	}
	int x=0;int len=0;
	x=p[x]; len++;
	while(x!=0){
		x=p[x];
		len++;
	}
	if(len==n){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 2176
<?php

$a = trim(fgets(STDIN));
$b = strlen($a);
$input = str_split($a);
$result = "No";
sort($input);

if (($input[0] == $input[1] && $input[2] == $input[3]) and ($input[2] != $input[1])) {
    $result = "Yes";
} 
echo $result;
?>

Measured memory_bytes: 4604
#include<cstdio>
#include<algorithm>
int main(){
    int a[3];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    std::sort(a,a+3);
    printf("%lld",(((a[0]&a[1])&(a[2]&1))==1)?((long long)a[0]*a[1]):0);
    return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v).begin(),(v).end()
#define COUT(x) cout<<(x)<<"\n"



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> vec(n+2,0);
    REP(i,n)cin >> vec[i+1];
    
    ll ans = 0;
    for(int i=0;i<n+1;i++){
        ans += abs(vec[i+1]-vec[i]);
    }
    for(int i=1;i<n+1;i++){
        COUT(ans+abs(vec[i+1]-vec[i-1])-abs(vec[i]-vec[i-1])-abs(vec[i+1]-vec[i])); 
    }
    return 0;
}

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

const int INF = 0x3f3f3f3f;

ll dp[105][100005], w[105], v[105], n, s;

ll solve(int i, int p) {
    if(dp[i][p] != -1)
        return dp[i][p];
    if(i == n or p == 0)
        return 0;
    ll a1, a2;
    if(p-w[i] >= 0) a1 = solve(i+1, p-w[i])+v[i];
    else a1 = -INF;
    a2 = solve(i+1, p);
    dp[i][p] = max(a1, a2);
    return dp[i][p];
}

int main() {
    cin >> n >> s;
    for(int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0, s) << endl;
}


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

int32_t main(){
	int n, x, m;
	cin >> n >> x >> m;
	unordered_map<int, int> mp, sum;
	int a = 0, b = 0, c = 0;
	int i = 0;
	while(mp.count(x) == 0){
		mp[x] = i;
		b += x;
		sum[i] = b;
		i++;
		x = (x * x) % m;
	}
	a = sum[mp[x]-1];
	b -= a;
	int numCycle = (n - mp[x]) / (i - mp[x]);
	b *= numCycle;
	int rem = (n - mp[x]) % (i - mp[x]);
	c = sum[mp[x] + rem - 1] - sum[mp[x] - 1];
	cout << a + b + c;
    return 0;
}

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

int main()
{
    int n;
    cin>>n;
    map<string,int>m;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        m[s]++;
    }
    cout<<m.size()<<endl;
    return 0;
}

Measured memory_bytes: 19196
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	int a,b,C;
	cin >> a >> b >> C;
	printf("%.4f\n%.4f\n%.4f\n"
			,a*b*sin((double)C/180*M_PI)/2
			,a+b+sqrt((double)pow(a,2)+pow(b,2)-2*a*b*cos((double)C/180*M_PI))
			,b*sin((double)C/180*M_PI));
	return 0;
}

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

struct item{
	int v;
	int w;
}a[101];

long long f[100001];

int main(){
	int N,W;
	scanf("%d%d",&N,&W);
	for(int i=1;i<=N;++i)
		scanf("%d%d",&a[i].w,&a[i].v);
	for(int i=1;i<=W;++i){
		if(a[1].w<=i)f[i]=a[1].v;
	}
	for(int i=2;i<=N;++i){
		for(int j=W;j>=0;--j){
			if(j>=a[i].w)
				f[j]=max(f[j],f[j-a[i].w]+a[i].v);
		}
	}
	cout<<f[W]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> par_num;

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
        par_num.assign(N,1);
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        par_num[root(rx)]++;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int n, m, k; cin >> n >> m >> k;
    UnionFind tree(n);
    vector<int> ans(n, 0);

    vector<vector<int>> a(n);
    vector<vector<int>> b(n);
    for(int i=0; i<m; i++){
        int A, B; cin >> A >> B;
        A--; B--;
        a.at(A).push_back(B);
        a.at(B).push_back(A);
        tree.unite(A,B);
    }


    for(int i=0; i<k; i++){
        int A, B; cin >> A >> B;
        A--; B--;
        b.at(A).push_back(B);
        b.at(B).push_back(A);
    }   

  vector<int> root_num(n,0);

  rep(i,n){
    root_num[tree.root(i)]++;
  }

  rep(i,n){
    ans[i] += root_num[tree.root(i)];
    ans[i]-=1;
    ans[i]-=a[i].size();
    for (auto nv: b[i]){
      if (tree.same(i,nv)) ans[i] -= 1;
    }
  }

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

    return 0;
}


Measured memory_bytes: 13816
//ABC85A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	string s;
	cin >> s;
	s.at(3) = '8';
	cout << s << endl;
	return 0;
}

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

typedef long long ll;
using namespace std;

#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define _repi(i, s, n) for(ll i = (ll)(s); i < (ll)n; i++)
#define REP(...) _overload(__VA_ARGS__, _repi, _rep,)(__VA_ARGS__)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007

int main(){
	ll n;	cin >> n;
	string s;	cin >> s;
	bool ans = true;

	if( n % 2 == 0 ){
		REP(i, n/2){
			if( s[i] != s[i + n/2] )	ans = false;
		}

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

	return 0;
}


Measured memory_bytes: 3588
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var NM = ReadSplitLong();
            var N = NM[0];
            var M = NM[1];

            var ans = 0L;
            if (N * 2 <= M)
            {
                M -= (N * 2);
                ans += N;
            }
            else
            {
                ans += M / 2;
                M = M % 2;
            }

            if (M >= 4)
            {
                ans += M / 4;
            }
            Println(ans);
        }

        static List<int> ReadLines(int n)
        {
            var l = new List<int>();
            for (int i = 0; i < n; i++)
            {
                l.Add(ReadInt());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 11348
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll t1,t2;cin>>t1>>t2;
    ll a1,a2,b1,b2;cin>>a1>>a2>>b1>>b2;
    ll p=(a1-b1)*t1,q=(a2-b2)*t2;
    if(p>0){
        p*=-1;q*=-1;
    }
    if(p+q==0){
        cout<<"infinity"<<endl;
        return 0;
    }
    if(p+q<0){
        cout<<0<<endl;
        return 0;
    }
    
    
    ll s=(-1*p)/(p+q);
    ll t=(-1*p)%(p+q);
    if(t==0)
        cout<<2*s<<endl;
    else
        cout<<2*s+1<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

int main(void)
{
    int l, r, d, cnt=0;

    scanf("%d %d %d" ,&l, &r, &d);

    for(int i=l; i<=r; i++)
        if(i%d==0)
            cnt++;

    printf("%d" ,cnt);

    return 0;
}


Measured memory_bytes: 3816
#include<bits/stdc++.h>
#define mk make_pair
#define f first
#define s second
using namespace std;
int n,m,p1,p2,dp[201][1001][1001];
map<pair<int,pair<int,int> >,int >m1;

vector<pair<int,int> >v;

int dfs(int d,int h,int w){
  int res=0;
  if(m1[mk(d,mk(h,w))])return m1[mk(d,mk(h,w))];
  if(d==v.size()) return 1;
  if(v[d].f<h&&v[d].s<w)
    res=max(res,dfs(d+1,v[d].f,v[d].s))+1;
  res=max(res,dfs(d+1,h,w));
  return m1[mk(d,mk(h,w))]=res;
}

main(){
  while(cin>>n,n){
    m1.clear();
    v.clear();
    for(int i=0;i<n;i++){
      cin>>p1>>p2;
      v.push_back(mk(p2,p1));
    }
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>p1>>p2;
      v.push_back(mk(p2,p1));
    }
    stable_sort(v.begin(),v.end(),greater<pair<int,int> >());
    for(int i=0;i<v.size();i++)swap(v[i].f,v[i].s);
    stable_sort(v.begin(),v.end(),greater<pair<int,int> >());
    cout<<dfs(0,1001,1001)-1<<endl;
  }
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int n;
int main(){
    cin >> n;
    cout << 180*(n-2) << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        K: u64,
        AB: [(u64,u64);N],
    }
    let mut AB = AB;
    AB.sort();
    let mut cnt = 0;
    for i in 0..N{
        let (a,b) = AB[i];
        cnt += b;
        if cnt >= K{
            println!("{}", a);
            break;
        }
    }
}

Measured memory_bytes: 6396
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N)]

dp = [0, 0, 0]
for n, p in enumerate(ABC):
	tdp = dp.copy()
	for i in range(3):
		for j in range(3):
			if i == j:
				continue
			tdp[i] = max(tdp[i], dp[j] + p[j])
	dp = tdp
	#print(dp)
print(max(dp))


Measured memory_bytes: 30580